Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split html forms?

Tags:

html

forms

I am wondering if it is possible to split html forms?

Basically I have a normal form

<form action="/post.php" method="post" id="postform">
    <label for="name">Name: </label>
    <input id="name" name="name" value=""/>
</form>

Then I have a ajax image upload, which includes it's own form due to how it works.

Then after that I want to have the submit button for the first form.

I know I can have a javascript submit button, but that shut's out anyone without Javascript. So I am wondering if it is possible to split a form into multiple groups?

e.g. I know this won't work, but it demonstrates what I want to do..

<form action="/post.php" method="post" id="postform">
    <label for="name">Name: </label>
    <input id="name" name="name" value=""/>
</form>

<!-- form for ajax image upload here -->

<!-- continuation of first form -->
<form action="/post.php" method="post" id="postform"> 
    <!-- this button should submit the top form -->
    <input type="submit" value="Submit"/>
</form>
like image 269
Hailwood Avatar asked Sep 11 '12 13:09

Hailwood


People also ask

How do you split a form in HTML?

The div tag is known as Division tag. The div tag is used in HTML to make divisions of content in the web page like (text, images, header, footer, navigation bar, etc). Div tag has both open(<div>) and closing (</div>) tag and it is mandatory to close the tag.

Can you have two forms in HTML?

HTML standard dictates no two elements can have the same Ids. You can use Javascript to change the Id/Name dynamically before you hook the connector to the target form.


2 Answers

In HTML5 its possible as pointed out at https://stackoverflow.com/a/8380229/556085:

Sample form:

<form id="formID" action="action" method="post">
    Text: <input type="text" value="some_id" name="some_name" />
</form>

And you place the submit referencing the form to submit via its ID where you want

<input type="submit" name="save" value="Save" form="formID" />
like image 67
KillerX Avatar answered Sep 20 '22 19:09

KillerX


You may have different forms which are separated via different form tags, with different ids, then you can fire the form submit event with javascript.

Without javascript on the client, I have no idea how to do it ...

like image 29
Mahdi Avatar answered Sep 20 '22 19:09

Mahdi