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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 2009-08-27 at 23:21 -0400, Adam Jimerson wrote:
> 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))
> > 
> > I'm sure that this is not the best/recommended way to do this but I'm
> > hoping someone here will point me in the right direction.
> 
> 

The best way I've found is to do something like this:

if(isset($_POST['submit']))
{}

Note that in-place of submit you can put the name of any form element. I
chose submit here, because every form should have a submit button. Note
also that this will only work if you have given your submit button a
name:

<input type="submit" name="submit" value="Submit"/>

Thanks,
Ash
http://www.ashleysheridan.co.uk




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux