Jump to content

Checking If A Button Was Clicked


murfitUK

Recommended Posts

I've been trawling for some scripts and came across two small examples that I want to use, but they had different ways of checking if a submit button had been clicked. These were just small bits of code so obviously I'll expand on them. But I would like to know what the difference is and which one is the best to use.Suppose the button is named "clicked".The first example had:if ($_POST['clicked']) { do this }The second had:if (isset($_POST['clicked'])) { do this }They both seem to do the same thing on the limited testing I have done. I've had a look through php.net but can't quite see what the difference is. Thanks.

Link to comment
Share on other sites

PHP throws a warning if you try to access a variable that has never been set. You might not see the warning if the server admins have suppressed error-reporting, but it's there, and it's something to keep track of. Good writers check all post/get data before trying to access it.

Link to comment
Share on other sites

Using isset() or !empty() is essential to good programming, yes. Note that isset returns true if a variable has been set to false, 0, or an empty string. It returns false if the variable has not been set. (Like a checkbox that didn't get checked, so it's not part of the POST data.) So what isset() tells you about your button will depend on your form and any javascript that goes with it.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...