开发者

What to use instead of if(isset($_POST['submit'])) for this.form.submit()?

开发者 https://www.devze.com 2022-12-23 19:44 出处:网络
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:

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
}

?>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号