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)?
2 Answers
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
}
Comments
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
}
<form name="myForm">or<input type="hidden" name="myHidden" value="something" />