I have a single page with multiple forms which may appear on it. Is there anyway of distinguishing between these forms in php (some kind of form iding system)?
Asked
Active
Viewed 1,012 times
2 Answers
5
You can use a hidden input. Example:
<form ...>
<input type="hidden" name="form_id" value="first_form">
</form>
<form ...>
<input type="hidden" name="form_id" value="second_form">
</form>
Then, in PHP, just look for that:
if ($_REQUEST['form_id'] == 'first_form') {
// first form
} else {
// second form
}

rid
- 61,078
- 31
- 152
- 193
5
There are many methods that you can use
Give the submit button a unique name or value for each form,
<input type="submit" name="form1" value="Submit">
if (isset($_POST['form1'])){
// form1 was filled in
}
Add a hidden input field
<input type="hidden" name="form" value="form1">
if (isset($_POST['form']) && $_POST['form'] == "form1"){
// form1 was filled in
}
Use a parameter in the action url.
<form action="index.php?form=form1" method="POST">
if (isset($_GET['form']) && $_GET['form'] == "form1"){
// form1 was filled in
}

Anigel
- 3,435
- 1
- 17
- 23