I am using PHP to process form data from a web page. How can I access the name of the form that was used to submit the form data? It does not seem to be available in the $_POST array.
Accessing the form name
Collapse
X
-
Tags: None
-
The name of the form is not passed with the form collection. So, if you have multiple forms pointing to the same page, you can do one of several things:
1. Include the name of the form in a hidden input field within each form.
2. Use different submit buttons, and check for the presence of each in the target page.
3. Use a hidden element in each form that will go to the same page, this way you can determine the form that was submitted. This should be sufficient, unless you don't have control over the submitting forms. If you don't, you have to explain to the people who DO have control over them, that you need some way to distinguish their requests.
4. If your forms come from different pages, use HTTP_REFERER to determine what page the request came from. -
Be aware that some ISP's do not allow and do not set the HTTP_REFERER, so it could be blank. Best is to pass it as a hidden field in the form.
Ronald :cool:Comment
Comment