[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Submit two forms on one page

Posted on 2011-03-06
6
Medium Priority
?
427 Views
Last Modified: 2012-05-11
I have two forms on a page. One is a PayPal form that submits information to PayPal, so the customer can complete the purchasee. The other form is sent to my server, to a php program that puts the user and sale information into a database. The second form has some input fields that the customer completes with their name and contact information as well as several hidden input fields.

I am using the following jquery code to populate the first form with the values entered into the second form. The code below works in transfering the values from myForm2 to myForm1, and the form is successfully sent to PayPal with the information.

But the second form, myForm2, does not post.

I am using the jquery.forms plugin, but I am open to any way the keeps the functionality of populating myForm1 with the myForm2 entries, and posts both forms.

<script type="text/javascript" src="js/jquery.forms.js"></script>
<script language="javascript">
      $(document).ready(function() {
            $("#button1").click(function() {
                  var First_Name2 = $("#First_Name").val();
                  $("#first_name").val( First_Name2 );
                  var Last_Name2 = $("#Last_Name").val();
                  $("#last_name").val( Last_Name2 );
                  var Email2 = $("#Email").val();
                  $("#email").val( Email2  );
                  var Cell_Phone2 = $("#Cell_Phone").val();
                  $("#night_phone_a").val(Cell_Phone2);
                  
      $('#myForm1').submit(function() {
      var options = { "success":function() { $("#myForm2").submit(); }}
      $(this).ajaxSubmit(options);
      return false;
      });
});
});
</script>
0
Comment
Question by:birwin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 16

Expert Comment

by:sjklein42
ID: 35045882
Ordinarily, when a form is submitted, that is the end of control for that web page.  Ajax is the exception.  Do your Ajax call first, then give control to the form submit (which probably does not return but goes to the response page from the form action).

<script type="text/javascript" src="js/jquery.forms.js"></script> 
<script language="javascript">
      $(document).ready(function() {
            $("#button1").click(function() {
                  var First_Name2 = $("#First_Name").val();
                  $("#first_name").val( First_Name2 );
                  var Last_Name2 = $("#Last_Name").val();
                  $("#last_name").val( Last_Name2 );
                  var Email2 = $("#Email").val();
                  $("#email").val( Email2  );
                  var Cell_Phone2 = $("#Cell_Phone").val();
                  $("#night_phone_a").val(Cell_Phone2);
                  
      var options = { "success":function() { $("#myForm2").submit(); }}
      $(this).ajaxSubmit(options);
      $('#myForm1').submit(function() {
      return false;
      });
});
});
</script> 

Open in new window

0
 
LVL 6

Author Comment

by:birwin
ID: 35047124
Thank you for the code. Unfortunatley it isn't producing the desired result.

Form 1 is a PayPal code that has to be submitted to PayPal, not using AJAX, as the client needs to complete the resulting PayPal forms.

myForm2 should be an AJAX posting to my server.

With your code the myForm2 is the page the client gets, but it is blank, since it only progesses the information. I need the myForm1 result (PayPal) to be shown to the client, and the myForm2 to be handled as an AJAX call to the server.
0
 
LVL 16

Accepted Solution

by:
sjklein42 earned 2000 total points
ID: 35048166
Just to see if it makes a difference, add "target=_blank" to the "form" tag for myForm2.  This is just a test to see if the problem may have to do with the target window of your form replacing the current page.

If you could post some more code (especially the FORM tags) , or provide a link, that would help.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 6

Author Comment

by:birwin
ID: 35050972
Hi sjklein42:

I tried adding the target, but it made no difference.

For access to the the problem page, please go to Link to Problem  This is an indirect link, since it is a client site.
0
 
LVL 16

Expert Comment

by:sjklein42
ID: 35051592
I don't think I can help.  A bit too complicated for me to unravel.  Tried.  Sorry.
0
 
LVL 6

Author Closing Comment

by:birwin
ID: 35059463
Thank you for your help. I ran the code through the W3 validator, and found some errors. I tinkered with the jQuery code and finally got it to work, although I am not sure which of the fixes I made solved it. But if it works, it works, and I am happy.
0

Featured Post

Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question