PDA

View Full Version : submitting 3 forms with 1 button



nickyfraggle
Jan 8th, 2010, 12:38 PM
Hello,

I have 3 forms on one page each with their own submit button. I think it would be really helpful if all 3 could be submitted at the one time, with 1 button, and I think I'll prob need Javascript to do this.

I want to submit the forms together, posting all the information to a php page that deals with it.

Is this possible? I'm using php.

Thanks,

Nicky

abduraooft
Jan 8th, 2010, 12:40 PM
I want to submit the forms together, posting all the information to a php page that deals with it.

Is this possible? I'm using php. Not possible with 3 forms. Can't you just include all the input elements inside a single form?

Philip M
Jan 8th, 2010, 12:50 PM
Try this:-


<script>
function submitallforms() {
setTimeout('document.forms[0].submit()',100);
setTimeout('document.forms[1].submit()',200);
setTimeout('document.forms[2].submit()',300);
}
</script>

<input type=button value="Submit" onclick="submitallforms();">

See also
http://www.codingforums.com/archive/index.php/t-172801.html



Headless corpse accused in court - Bedfordshire On Sunday

nickyfraggle
Jan 8th, 2010, 12:56 PM
Thanks - the reason I have 3 forms is for layout. There's a lot of information, so I have 2 forms next to each other going down the screen in columns and 1 form at the bottom going across both columns for a text area. Having 3 x submit buttons is annoying as you get confused as to which one to click, and also you can only update 1 section at a time. It's really frustrating! There's so much info in the forms that having them going right down the screen is way too long.

Will try your idea Phillip - thanks. How will the php at the other end know when each form is posted though? I'm not good with client side stuff!

If there's another way I can do this I'm all ears... obviously this isn't an ideal way of doing it.

Thanks - really appreciate your time and help.

Nicky

abduraooft
Jan 8th, 2010, 01:03 PM
It's really frustrating! There's so much info in the forms that having them going right down the screen is way too long. How about showing them separately(3 different pages or on the same page using if conditions) ?

@Philip : Doesn't the submit action of one form effect the sequential execution of that script?

nickyfraggle
Jan 8th, 2010, 01:25 PM
@abduraooft That would work, but would mean you can't see the rest of the information which isn't ideal as it's all related. The problem is because I can't span div's with 1 form tag going through several divs, however if I wrapped the different sections in fieldsets, and then used css to position those fieldsets...I might be able to mimic the layout but using 1 form.

I've had a play and so far so good. If I can get it to work cross browser ok (can't see it being too much of an issue except maybe in good old IE6!) it might be far simpler to do it this way.

Appreciate your help - its helpful to have people to chat to and bounce ideas off!!

Nicky

Philip M
Jan 8th, 2010, 02:08 PM
@Philip : Doesn't the submit action of one form affect the sequential execution of that script?

Not sure - I did say try it. It might or might not work. I rather assumed that the three forms had three different actions. If it does not work then you are right - not possible!