Suppose I have two form in individual pages. One is Called ParytForm.html and second one is clientForm.html. And I have a single PHP file which contains two php functions. One is PartyForm() and second one is clientForm(). Now is it possible, when user fill the form form PartyForm.html then partyForm() is called. and when user fill the form from clientForm.html then clientForm() is called. Thanks
5 Answers
You can send a variable by GET method ("do=partyform"), check it in php and call right function.

- 4,139
- 5
- 37
- 61
In one form put
<input type="hidden" name="from" value="ParytForm.html" />
and in the other:
<input type="hidden" name="from" value="clientForm.html" />
then in your PHP code distinguish your input:
if ('clientForm.html' == $_POST['from'])
{
// do stuff
PartyForm();
}
else if ('ParytForm.html' == $_POST['from'])
{
// do other stuff
clientForm();
}
I adapted ParytForm.html
for fun ;-)

- 33,871
- 11
- 91
- 99
To do this, you will need some way of the PHP program to distinguish between the two requests. This can be done by adding a parameter to the URL the form is submitting to, or changing the name of the submit button. I tend to prefer the URL method though, because it is cleaner.
for example
Form 1 could be
<form method="phpfilename.php?dofunction=1">
Form 2 could be
<form method="phpfilename.php?dofunction=2">
Then, on your PHP file, you could check which form is sent using
$form = $_GET['dofunction'];
if ($form == '1') doFunction1();
else if ($form == '2') doFunction2();

- 54,176
- 10
- 96
- 129
-
You do [not want to use $_REQUEST](http://stackoverflow.com/questions/1931587/is-it-wrong-to-use-request-for-data). – Linus Kleen Dec 19 '10 at 14:54
-
True. Lazy coding using a catch-all! Example code changed to reflect. – Codemwnci Dec 19 '10 at 15:04
You can do this multiple ways, one way is to include a hidden field in each form, and then use a conditional after you submit to run the right function.
Your html code below
<form action="action.php" method="post">
...
<input type="hidden" name="formName" value="PartyForm">
<input type="submit" value="Submit">
</form>
<form action="action.php" method="post">
...
<input type="hidden" name="formName" value="ClientForm">
<input type="submit" value="Submit">
</form>
and then in your action.php or whatever you call the page you submit to
if($_POST['formName'] == "PartyForm"){
partyForm();
}else if$_POST['formName'] == "ClientForm"){
clientForm();
}

- 2,817
- 3
- 24
- 32
The best way to do this (I think) is to use the PHP include()
function. Use your forms inside a .php file (which can include HTML only), and include the functions file in both form files.
Then, just use action="clientForm()"
to call the function when the form is submitted.

- 2,518
- 6
- 30
- 50