Re: Re: Best way to test for form submission?

From: Date: Fri, 28 Aug 2009 15:03:05 +0000
Subject: Re: Re: Best way to test for form submission?
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-297423@lists.php.net to get a copy of this message
2009/8/28 Eric <eric@lightstudios.co.cc>: > > ----- Original Message ----- > From: "Stuart" <stuttle@gmail.com> > To: "Eric" <blueray2048@yahoo.com> > Cc: <php-general@lists.php.net>; "Adam Jimerson" <vendion@charter.net> > Sent: Friday, August 28, 2009 10:10 PM > Subject: Re: [PHP] Re: Best way to test for form submission? > > > 2009/8/28 Eric <blueray2048@yahoo.com>: >> >> ----- Original Message ----- >> From: "Adam Jimerson" <vendion@charter.net> >> To: <php-general@lists.php.net> >> Sent: Friday, August 28, 2009 11:21 AM >> Subject: [PHP] Re: Best way to test for form submission? >> >> >>> On 08/27/2009 11:09 PM, Adam Jimerson wrote: >>>> This question might give away the fact that I am a php noob, but I am >>>> looking for the best way to test for form submission in PHP. I know in >>>> Perl this can be done with >>>> >>>> if (param) >>>> >>>> but I don't know if that will work with PHP. I have read the Learning >>>> PHP 5 book and the only thing that was mentioned in the book was the use >>>> of something like this >>>> >>>> print "<p>Hello >>>> ".$_POST['username']."</p>"; >>> >>> Sorry copied and pasted the wrong line (long day) >>> >>> if (array_key_exists('username',$_POST)) >> >> Here is another way >> >> if (isset($_POST['username']) && $_POST['username'] != >> '') >> { ... > > If you use this method then you'll completely ignore a form submission > if they've forgotten to enter a username. Detection and validation are > two distinct steps and should be treated as such. > > Stuart > thanks, > > how about this way > > $submit = isset($_POST['submit']) ? true : false; > if ($submit) >  { ... Why the variable? It's unnecessary, as is the ?: operator - isset returns a boolean. if (isset($_POST['submit'])) will achieve the same result. -Stuart -- http://stut.net/

« previous php.general (#297423) next »