1

I have a payment button on a page that submits info to a payment processor and on the same page there is a form with some custom fields that updates a contact info when u submit it.

Im using a jquery script that submits the payment button and at the same time POSTS the values of the form to the updatecontact php script.

But its not working, its not posting the values to the updatecontact php script.

Please take a look at the code below to see if u can discover what am i doing wrong.

http://jsfiddle.net/QunPb/1/

The URL where the code is: http://ofertasclaras.com/envio.php

3
  • 3
    You can't use ajax to POST across domains, so this script simply won't work in a jsFiddle. What is the URL of the page you're actually trying to run this in? Commented Nov 20, 2011 at 21:32
  • Have you tried doing the form submission within your jQuery function as a callback? Commented Nov 20, 2011 at 21:34
  • The URL is this one: ofertasclaras.com/envio.php @Smamatti can u show me an example ? Commented Nov 20, 2011 at 21:37

4 Answers 4

2

You're trying to create a form that has multiple submit actions.

cURL won't work because then your server is posting to dineromail, not the visitor's browser (Unless you actually want your server to make the purchase?) ;)

Instead, use jQuery to add an ajax request to the form submit. By making the ajax request not asynchronous, it will complete that request before it submits to the form's main action (dineromail) using "return true".

$(document).ready(function() {
  $('#dinero-form').submit(function() {
    $.ajax({  type: "POST", async: false, url: 'http://ofertasclaras.com/actualizar.php',
              data: { email: $('#email').val(),nombrecompleto: $('#nombrecompleto').val(),  direccion: $('#direccion').val(), ciudad: $('#ciudad').val(), provincia: $('#provincia').val(), codigopostal: $('#codigopostal').val(), casaodepto: $('#casaodepto').val(), gelypilas: $('#gelypilas').val() }
    });
    return true;
  });
});
Sign up to request clarification or add additional context in comments.

Comments

0

In your fiddle, the selector that starts things off won't match anything:

$('#dinero-form')

Not sure if it's the only problem in your page, but you'll probably need to update the form tag like this:

<form action='https://argentina.dineromail.com/Shop/Shop_Ingreso.asp'
  method='post' id='dinero-form'>

1 Comment

I forgot to add it on the fiddle but im using it on the page, jsfiddle is updated. This is not the problem
0

Scripts are attached to pages; requests are associated with the page for the script that makes the request. When you submit a form, the new page replaces the old. This can interrupt the request.

Instead of using AJAX to submit a request client-side, you can do it server-side. A common approach is to create a service class (implemented using cURL), so you can access the HTTP service using an OO interface. Service methods become instance methods. Request parameters are passed to service methods as an array or an instance of some request class that you write.

1 Comment

i was originally using curl but it was not redirecting, can u suggest a code so i can test it and report back?
0

Would this logical flow work in your situation:

1) Capture the form post using AJAX 2) Send your required data to your url and return false in the form 3) When your page return success, submit the form to the payment gateway page

// prime your element with a state that you can check on later
// in thise case 'captured' via the .data() method, set to false (not yet captured by your script)
$('#dinero-form').data('captured',false).submit(function(){
 // bind to the submit event of the form and return false by default unless
 // captured is true, which means your form has been captured by your page
 // and you're happy to pass the form data on to the gateway (be sure this is over ssl on your own server, etc, as necessary for appropriate security)
 var $this = $(this), data = $this.serialize(), captured = $this.data('captured');

 // if not captured, send to your script
 if(false === captured) {
   $.post('/url-for-your-data/',data,function(response){
     // change this to your url where you want to capture it
     // if you are returning json, use something like the below (with your own values)
     // to determine if it was successful or not at storing the data you want to capture
     if(response.success) {
       // if it succeeded, then tell the form it has been captured and then trigger
       // the original submit to the form action defined in your form
       $this.data('captured',true);
       $this.trigger('submit');
     } else {
       // handle form validation here
     }
   },'json');

   // return false so the form doesn't submit and you can wait for the response
   // usually a good idea to show a loading/activity graphic at this point if it's not quick
   return false;
 } else {
   // otherwise it was captured, and you can send to the gateway now
   return true;
 }
});

** WARNING **: While this may work while JavaScript is turned on, you would benefit from submitting this to your page first, to capture it and set any session variables and THEN sending it to your gateway with a unique ID for the transaction in some way so that you can match it up when the user is returned to your site. (If that's appropriate.)

** WARNING **: You should always send personal information over SSL, so make sure you have this kind of thing accounted for and make sure your users know that their data's secured to your server AND the gateway they are using :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.