What to use instead of if(isset($_POST['submit'])) for this.form.submit()?
I want to run a particular block of PHP开发者_Go百科 if the user submits a form. It works if I use a submit button with name="submit" and:
<?php
if(isset($_POST['submit'])) {
code to run
}
?>
I don't know anything about javascript, and I want the code to run if the user changes a dropdown menu. If I make the first line of the dropdown
<select name="dropdownname" onchange="this.form.submit()">
the form appears (I haven't tested it) to submit if the user changes the dropdown choice. However, if I do this, the if(isset($_POST['submit'])) PHP code doesn't run. Is there a PHP if statement I can write that will respond to the form being submitted even though it's being submitted by a change in the dropdown and not a submit button?
You may want to check directly for:
if(isset($_POST['dropdownname']))
Even you can use something like:
if(count($_POST)){
// form validation
} else {
//...
}
you should always check $_SERVER['REQUEST_METHOD'] instead of particular field name
And in case if this dropdown used to display some data, not to write to the database, GET method should be used instead.
<?php
if(!empty($_POST))
{
code to run
}
?>
精彩评论