tags:

views:

944

answers:

2

I need to have multiple forms in the same webpage, all of them POSTing to itself and then performing different actions depending on the type of form.

What's the best way to achieve this?

To be more specific, the page shows the details of an event, with a form to subscribe (a drop-down box) and another form for each of the subscribed persons that allows them to unsubscribe (it's just a button).

+8  A: 

A few ideas for you:

  1. A hidden field in each form

    <input type="hidden" name="formname" value="firstForm" />

  2. Or setting the action url to include a querystring

    <form action="mypage.php?formtype=firstForm" ...>

  3. Named buttons so you know which was clicked.

    <input type="submit" name="firstForm" value="Submit" /> And then check that firstForm (et al) has been returned

Edit: the code-sampling on SO doesn't seem to work for HTML properly. (Worryingly) it's not escaping forms, so I've cut the examples way down (sorry and I hope you understand what I'm saying!)

Oli
A: 

You could just have a hidden input for each form containing a formid. Then, when the page processes, you can tell which form was submitted.

Or am I misunderstanding your question?

zigdon