if (isset($_POST['submit'])) Since every form has a Submit button, an easy way to check to see if a form has been submitted is to see if there's $_POST data for the Submit button. The data's just the label on the button, which isn’t important. What's important is simply the existence of $_POST['submit'] , which tells us that the form has been submitted. Just make sure that 'submit' matches up with the id attribute of the Submit button in the form code.
So why don't we check to see if real form data's set, instead of the Submit button?
It would work perfectly fine to check $_POST['subject'] or $_POST['elvismail'] , but only for this particular form. Since every form has a Submit button that can be consistently named submit, checking $_POST['submit'] gives you a reliable way to check for form submission in all of our scripts.
(from: Head First PHP and MySQL P202/242)
No comments:
Post a Comment