1

I have one page with a form that submits to a second page with its own form.

In the second page,

if ($_SERVER['REQUEST_METHOD'] === 'POST') {

always returns true and the if condition executes - I'm not sure if its because its called from a first form itself - but normally that's what I do to check the form is submitted, and it works as expected. Ie, as soon as the page/form opens, it executes the code inside the condition, when obviously it should not.

I need to be able to check in the second form when it is submitted itself ?

Its just a standard short form with its own button

<input type='submit' value='GO!'>

It comes from a first form with its own button

<input type='submit' value='Delete'>
yoyoma
  • 3,336
  • 6
  • 27
  • 42
  • Does the second form action on itself ? Or does it action on another file. Even if the action is set to itself you can add a hidden field for second form and check whether that is set and you will know whether it was submitted – Hanky Panky Feb 12 '15 at 06:00
  • Post the entire code. – Yuva Raj Feb 12 '15 at 06:01
  • yes it actions itself - true I can add another hidden field, but i'm not sure why it's necessary – yoyoma Feb 12 '15 at 06:01
  • Because you have to differentiate between the two forms if everything actions on one place. Or you could name the submit button somerhing else – Hanky Panky Feb 12 '15 at 06:10

2 Answers2

1

You can try this,

<form method="post" action="">
<input type="submit" name="submit" value="Go!">
</form>

Php code :

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

 }
Yuva Raj
  • 3,881
  • 1
  • 19
  • 30
0

Just noting that I solved this by checking for the name of the submit button, by adding the name:

<input type="submit" name="delete" value="Go!">

Then checking both

if (($_SERVER['REQUEST_METHOD'] === 'POST') && (isset($_POST['delete']))){
yoyoma
  • 3,336
  • 6
  • 27
  • 42