Thursday, December 8, 2011

how to use multiple forms on a single page

just name the submit button like this


1st form
<form action="abc.php" method="post"> 
<input type="text" name="abc">
<input type="submit" name="abc">
</form>
2nd form

<form action="abc.php" method="post"> 
<input type="text" name="def">
<input type="submit" name="xyz">
</form>
process the firm results
<?php
if(count($_POST)){
if (!empty($_POST["abc"])){
run your code here for 1st form
}
elseif(!empty($_POST["xyz"])){
run your code here for 2nd form
}
}
?>

you can place as many forms on a single page. As long as the submit name is different, only 1 form will be processed at a time.

No comments:

Post a Comment