Skip to content Skip to sidebar Skip to footer

Html Php Identifying The Form Posting Data

I have a php page which has multiple form tags. each form is dealing with a specific tab. It is simply a search but each tab provides a search of either date, number, or name. eac

Solution 1:

I would suggest adding a hidden input field for each form specifying the form name:

<inputtype="hidden" name="formname" value="invoice" />

Then you can get this with the $_POST['formname'] variable.

Solution 2:

You could, for one, in each submit button add a name and value, like so:

<form><inputtype="submit"name="action"value="search_invoice" />
   ... 
</form><form><inputtype="submit"name="action"value="search_customer" />
   ...
</form>

then in your php

switch($_POST['action']) {
   case'search_invoice':
      // ur codebreak;

   case'search_customer': default:
      // ur codebreak;
}

Be aware though, older versions of firefox doesn't properly submits the key => value pair of input type submit.

Another solution I usually use is to put an <input type="hidden" name="action" value="your_customAction" />

Solution 3:

One way is to store a different hidden input in each form, and then check for that hidden input on the server side to figure out which form it is.

<inputtype="hidden" name="formname" value="invoice" />
<inputtype="hidden" name="formname" value="customer" />
<inputtype="hidden" name="formname" value="customer2" />

Solution 4:

  1. Search should be performed using GET method, not POST
  2. no name attribute being sent to the server.
  3. If each tab provides a search of either date, number, or name - why don't you have the names of the search fields accordingly: "date" for the date search etc.?

Solution 5:

You should have different name of submit button in all the forms.

EDIT:-

If you have only one element in each form your best bet is to use @Petter's solution because IE having bug with the single text element- That it is if you submit the form using the enter key the submit button will not set in $_POST.

But if you have more than one element in the forms you can consider the choosing different name for submit buttons.

Post a Comment for "Html Php Identifying The Form Posting Data"