Link to home
Start Free TrialLog in
Avatar of jasch2244
jasch2244

asked on

Multiple forms on a single page, how do you tell which form has been submitted?

I know this is something that is probably pretty simple but... if you have multiple forms on a single page that are hidden/shown with jquery, javascript or whatever what is the best method for determining which form was submitted. Cfif statements, switch statements and what are you looking for in the form (hidden id, submit button name) etc.?

Avatar of sajayc
sajayc
Flag of New Zealand image

Hi,

In your form tag, set the name field differently for each form.
This is particularly useful for javascript.
Also you can name the submit buttons differently if that is easier for you.
Then on the page you submit to you can reference by the form name or button name.

<form name="form1" action..........><input type="submit" name="submit1"></form>
<form name="form2" action..........><input type="submit" name="submit2"></form>
<form name="form3" action..........><input type="submit" name="submit3"></form>

Hope this helps.
Avatar of jasch2244
jasch2244

ASKER

And you would write what on the action page FORM.submit1 etc.? and it will take?
Avatar of Dave Baldwin
I would use different 'action' pages.  Then if they need to end up on the same page, redirect them.
SOLUTION
Avatar of sajayc
sajayc
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If i try and reference the #FORM.submit1# I get an undefined error. In other words it is not picking up the name of the submit button. Nor will it pick up the name of the form either.
Hi ,
Can you output this variable?
#form.formfields#

This should give you a list of all the fields.  Although, if they do not click the submit button it will not come through.
Ahh yeah.... I did not have form set to post... I'm an idiot! Thanks for your help
Instead of the elseif's can I use your method on switch statements? Which is quicker or more efficient?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial