简体   繁体   中英

Is it possible to submit 2 forms together as POST 1 action

I have 2 forms. One called clientcapture and one called quotecapture.

At the end of client capture are 4 tabs which the user clicks to choose between different types of quotes. When they click on the tabs I wipe quotecapture with the following function:

$("#quotecapture")[0].reset();

Obviously I do not want to reset clientcapture as this contains the user information.

This leaves me with a problem. I would like to POST the data as one request to the action page so that I can link the quote to the client based on their entries into a database. Once entering the client I wanted to retrieve the insert_id to tie to the quote.

I tried the following but obviously not the desired affect. Only 1 form submits, or at least - one overrides the other.

$( "#submit" ).click(function() {
  $( "#quotecapture" ).submit();
  $( "#clientcapture" ).submit();
});

Any suggestions on either how to improve the reset so that I can have 1 form or how i can somehow merge the forms and submit together would be appreciated.

Thanks

您可以将两种形式的值存储到变量中,并使用$ .ajax()函数将其发送到服务器。

I know this may not be very orthodox, but here's a simple take on it:

$( "#submit" ).click(function() {
  $( "#quotecapture" ).submit();
  secondformbutton.click();
});

where secondformbutton is the submit button for the second form, aka:

var seconfformbutton = $('#clientcapture').find('.submit'); 
//or something along these lines. 

I think this should work, as the form will simply click the submit button for the other one.

Also, something that could make your code above work is by starting it with preventDefault, (this should override the default submit action, then carry on the two actions specified below). aka:

$( "#submit" ).click(function() {
  event.preventDefault();
  $( "#quotecapture" ).submit();
  $( "#clientcapture" ).submit();
});

Suppose you merge these two form into one form... and just let it show as two forms by using css... means there will be one form action and multiple input box arranged in tabs like clientcapture and quotecapture.

Suppose you have one input/textarea for clientcapture and another input/textarea box for quotecapture and with one submit action you post the form to some action... In that action you get the clientcapture and quotecapture in diffrent variables...

like

$clientcapture = $post['clientcapture'];
$quotecapture  = $post['quotecapture '];

now use $clientcapture to save in db by insert query and take the insert an if of the query... And then save $quotecapture variable value in the bd by insert statement by using the insert id of clientcapture.....

Let me know yopu got my point or not and also let me know am I understand your problem well to be able to solve...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM