Jump to content

How to differentiate between multiple forms


Di Nimkii

Recommended Posts

Yes, Im trying to have multiple forms on one web page. Then when you submit each one have php differentiate between which form submitted the results.. to process and output what its processed. All on one page! Hint: I know you give <form> and id.. but hopefully you dont need javascript and can use php to check the name of the form, so it responds differently with each forms results. Thank you

Link to comment
Share on other sites

Just use inputs in the form to identify it.

 

In form 1:

<input type="hidden" name="action" value="form1">

In form 2:

<input type="hidden" name="action" value="form2">

On the server side:

$action = isset($_POST['action']) ? $_POST['action'] : '';
switch($action) {
  case 'form1':
    // Do processing for form 1
  break;
  case 'form2':
    // Do processing for form 2
  break;
  default:
    echo 'Invalid form';
}
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...