0

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)?

1
  • <form name="myForm"> or <input type="hidden" name="myHidden" value="something" /> Commented Aug 28, 2013 at 11:48

2 Answers 2

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
}
Sign up to request clarification or add additional context in comments.

Comments

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
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.