0

I have one page with a simple post form

<form name="click" action="UserOrders.php" method="post">
     <input type="hidden" name="amount" value="<?php echo $total ?>">
     <input type="image" src="/Templates/images/UpdateButton.png" name="submit">
</form> 

and the only thing I want to check is if it submits.. In the other page "UserOrders.php" I just wrote

<?php
if ($_POST['submit']){
    echo $_SESSION['ID'];
}

It seems to me irregular that it doesn't work and I would like another set of eyes to check it out. (if i put the echo $_SESSION['ID'] outside the brackets, it works.)

3 Answers3

0

An input type="image" only defines that image as the submit button and not as an input that can carry over a value to the server. source

An alternative way to see if the form was submitted is to check $_SERVER['REQUEST_METHOD']

if ('POST' === $_SERVER['REQUEST_METHOD']) {
    // submitted
}
Community
  • 1
  • 1
John Conde
  • 217,595
  • 99
  • 455
  • 496
0

I agree with the previous answer. You are not actually putting any information to the form and therefore there is nothing for the new form to react to. $_POST['submit"] is looking for data that was sent and not for the method of sending.

morantis
  • 106
  • 8
0

There's no actual submit button. You need a

<form action="UsersOrders.php" method="POST">
    <input type="whatever you want" name="input">
    <input type="submit" name="submit">
</form>

Now if you go into UsersOrders.php and do what you did before:

if($_POST['submit']) {
    echo $_POST['input'];
}

You will actually get some input.

Doug Leary
  • 119
  • 1
  • 5