1

so I'm working on a site, I currently have:

<form method =post action=process.php>
      <form method = get action = process3.php>
           <input type=submit value = add name = action/> 
      </form>
</form>

is it possible to add a attribute to control which form this input calls? For reasons un-mentioned above I am unable to simply use just one method

ssturges
  • 47
  • 1
  • 1
  • 4
  • You can use jQuery to handle these sorts of problems, I don't think there is any HTML mark up that can handle this kind of logic. – rfoo Sep 24 '13 at 02:11
  • @rosscowar I doubt jQuery can fix the fact that it is invalid HTML, most browsers are going to choke on nested `form`s and produce undefined behaviour. –  Sep 24 '13 at 02:16
  • @LegoStormtroopr no no no I'm not suggesting he leaves the HTML invalid I'm saying jQuery can handle whatever his logic is. – rfoo Sep 24 '13 at 02:18

3 Answers3

1

No. Forms can't be nested like this. That is invalid HTML. Moreso, its impossible to GET and POST data at the same time.

The submit action is strongly tied to its parent form, so I'd recommend writing your forms as siblings, then putting the field in the appropriate one and giving each form its own submit input.

<form method =post action=process.php>
     <input type=submit value = add name = differentAction/>
</form>

<form method = get action = process3.php>
     <input type=submit value = add name = action/>
</form>
Community
  • 1
  • 1
  • Whereas I agree that the forms cannot be nested, it is possible to send GET and POST data together. If the form method is POST and the GET data is in the action attribute as part of the query string you can access both. – Crackertastic Sep 24 '13 at 02:18
  • @Crackertastic But any data in the query string would have to be either put in on the server side, or somehow injected via javascript. However the data would still be `POST`ed to the site. The action would be POST, and thats the action the browser would send, not both. –  Sep 24 '13 at 02:24
  • Yes you would have to doctor the query string to get both, and the browser will only submit the form data in one form or the other. I construed your answer as suggesting that the data could only accessed via $_POST or $_GET, but not both, on the server side. I wanted to clarify that in case the OP had come to the same conclusion. – Crackertastic Sep 24 '13 at 02:29
1

You cannot nest forms like you do. You can submit forms from outside.

<form id="myform1" name="form1" action="" method="post">
    <input name="field1" value="form1" />
</form>
<form id="myform2" name="form2" action="" method="post">
    <input name="field2" value="form2" />
</form>

<input type="submit" form='myform1' value="submit1" />
<input type="submit" form='myform2' value="submit2" />

You can also add input fields outside the form tag

add input to form 2:

<input type="text" name='outside' value="outside" form='myform2' />
Daniel
  • 4,816
  • 3
  • 27
  • 31
0

Unless you are using way more sophisticated methods for controlling your forms the best way is to keep your submit action within the corresponding <form> </form> tag.

This might prove to be helpful depending on what you are trying to accomplish:

Submit multiple forms with one submit button

and this:

http://jquery.malsup.com/form/#getting-started

Community
  • 1
  • 1
BluePython
  • 1,635
  • 3
  • 24
  • 35