Forum Moderators: open

Message Too Old, No Replies

HTML <form> inside a <form>

         

Gian04

2:33 pm on Sep 7, 2009 (gmt 0)

10+ Year Member



I have a page with 2 submit buttons


<form>
Main Category [Another submit button (another form) here with value "change"]
Sub Category
<select>
.....
</select>
...
<input type="submit">
</form>

IE dont accept it, but FF works fine. How can I make it work in IE or how can I rewrite my form wherein I need a submit button (form) inside a form.

rocknbil

5:08 pm on Sep 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A form inside another form is invalid HTML and if it's working, it's only working because the browser is trying to make sense of it. However, there's lots of ways to manage this, but you'd have to offer up a little more info - mostly, how you're managing it on submit.

The two ways are first to make them two separate forms. If you use tables for layout, you can't nest them between rows, you have to have the forms fully contained within a cell or their own table:

<form>
<table>
</table>
</form>

<table>
<tr><td>
<form>
</form>
</td></tr>
</table>

If you can't make two forms, you can make program logic function based on which button was clicked by naming your buttons.

<form>
<input type="submit" name="action-a" value="Action A">
<input type="submit" name="action-b" value="Action B">
</form>

So whether you're using PHP, perl, whatever,

if (isset($_POST['action-a'])) {
// perform action a
}
else if (isset($_POST['action-b'])) {
// perform action b
}
else {
// Default action, which is likely to re-output the form
// with a message to select a button
}

If someone hits enter to submit the form "default action" is executed. Depending on the scenario, it may just be a duplicate of action A or B.

if (isset($_POST['action-a'])) {
// perform action a
}
else {
// Default action, which is B
}