Michael
Michael

Reputation: 49

Form action with PHP

I have a form, and I am trying to use the input to append to the form action. Here is my form code:

<form ACTION="_update/update.php?orderId=<?php $_POST['orderId']; ?>" name="msChangeForm" method="POST">
  <fieldset>
    <p>
      <label for="orderId">What is you order number?</label><br />
      <input name="orderId" type="text" id="orderId" value="" />
    </p>
    <p>
      <input type="submit" value="Next"/>
    </p>
  </fieldset>
</form>

I keep getting this error:

( ! ) Notice: Undefined index: orderId in C:\wamp\www\ms\test.php on line 48 Call Stack #TimeMemoryFunctionLocation 10.0020140184{main}( )..\test.php:0 " name="msChangeForm" method="POST">

Even though I get the error, the form works. I know I need some PHP code for this form, but I have no idea what to use.

Upvotes: 0

Views: 262

Answers (2)

Maxim Khan-Magomedov
Maxim Khan-Magomedov

Reputation: 1336

When you first load the page, it's requested using the HTTP GET method, so $_POST is empty.

The simplest workaround is to replace $_POST['orderId'] to isset($_POST['orderId']) ? $_POST['orderId'] : ''.

Upvotes: 3

Pitchinnate
Pitchinnate

Reputation: 7556

It means $_POST['orderId'] is empty. So it is submitting to _update/update.php?orderId= with no order id. However it works because you then submit the form and have the user input orderId so you should only the notice the first time you load the page. You don't need it in the action anyway, that would actually be $_GET['orderId'] not post.

Upvotes: 0

Related Questions