简体   繁体   中英

if(isset($_POST['submit'])) not working

I know there are cases on this, however I tried their method, but it didn't work for me.

Here is the code for isset: I tried placing this statement before <head> tag and within <body> tag but don't think it made a difference. This code resides in the same php file as the the submit button.

<?php if(isset($_POST['action'])) {
    echo "testing";
    exit();
}?>

Here is the form & submit button within form

<form name="createCaseForm" method = "post" action = "<?php echo url_mgt::getActionURL(); ?>" id="case-form" novalidate="novalidate">
    ...
    <td colspan="1"><button style="float:right;" name="action" type="submit" value="create_case_submit">Submit</button></td>
    ...
</form>

I'm not sure if using <button> instead <input> of would make a difference. I also did if(count($_POST) > 0) and it didn't work. I'm not sure what I'm doing wrong. When I run the file, it doesn't echo "testing", but instead went straight to the next page. My apologies if it's just a minor matter, but I tried methods posted in forums, but none seems to work.

I've tried to do this:

if(isset($_POST['action']) == 0) {
  echo "Testing";
} else {
    echo "Testing2";
}

It displays testing when the page is being loaded, however when i click on the submit button, I was hoping to see testing2 being printed. Am i right to say that after clicking the submit button, the page would not reload twice? So there is no way to check if the submit button is being posted?

I was having the same problem as above, if(isset($_POST['submit'])) not working when submitting a form. Setting the name to action didn't work for me. The solution was to assigned the submit to the name field of my form's input element. Here I present a MCVE tested in Firefox.

Kf

index.html

<html>
  <body>
    <form action="learnphp.php" method="post">

      <table border="0">

    <tr>
      <td>Name</td>
      <td align="center"><input type="text" name="username" size="30"/></td>
    </tr>   

    <tr>
      <td>City</td>
      <td align="center"><input type="text" name="cityaddress" size="30"/></td>
    </tr>

    <tr>
      <td><input id="radio1" type="radio"  name="selector"
             value="op1" /> </td>
      <td><input id="radio2" type="radio"  name="selector"
             value="op2" /> </td>         
    </tr>

    <tr>
      <td colspan="2" align="center"><input type="submit"
      name="submit" value="SubmiT"/></td>
    </tr>

      </table>

    </form>
  </body>
</html>

learnphp.php

<html>
  <head>
    <title>Information Gathered</title>
  </head>
  <body>

    <?php
       echo "<p>Data processed \"NOW\"</p>";      

       echo "<p>Let's observe: </p>";

       if(isset($_POST['submit'])){
           echo "submit set<br>";
           echo "Submit value=" . $_POST['submit'] . "<br>";
       }
       else echo "ERROR submit not set<br>";

       if(isset($_POST['selector'])){
           echo "Selecter set<br>";
           echo "Radial selection value=" . $_POST['selector'] . "<br>";
       }
       else echo "ERROR Selector not set<br>";

    echo "</br>";
    ?>
  </body>
</html>

Output:

Data processed "NOW"

Let's observe:
submit set
Submit value=SubmiT
Selecter set
Radial selection value=op2

You need a form field named action

<input type="text" name="action"/>

Also, make sure that url_mgt::getActionURL() is outputting the correct URL to submit to

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM