2

I want redirect after my form submission to the payment url of pay by group.

I was try bellow code but problem is that my form is submitting but i am not able to redirect.

See the bellow code snippet.

jQuery('.containerdddd' ).click(function() {
jQuery('#gform_29' ).submit();
window.location.replace("https://lets.paybygroup.com?merchant=abcd&purchase_description=Great%20rental%20for%203%20people%20with%20lake%20view.&purchase_link_url=http%3A%2F%2Fexample.com%2Fproperty&purchase_currency=CAD&purchase_cost=20&purchase_inventory_id=ESCAPE-23&purchase_name=ssss&purchase_image_url=http%3A%2F%2Fexample.com%2Fpicture.png&mixpanel=14b1230ef5970-091fdb2f9ca03e8-45574336-100200-14b1230ef5b86");
});  

can any one tell me how to this using any other option like ajax and something else.

bcesars
  • 1,048
  • 1
  • 17
  • 36
Sanjay Nakate
  • 1,888
  • 5
  • 33
  • 67

3 Answers3

2

You could use ajax to submit your form:

$('.containerdddd' ).click(function() {
    var form = $("#gform_29");
    var actionURL = form.attr("action");
    $.ajax({
        url: actionURL,
        data: form.serialize(),
        cache: false,
        success: function(result){
            //if the submit was successful, you redirect
            window.location.href = yourURL;
        },
        error: function(){
             //your error
        }
    });

});  

That is something basic that could help you start doing what you need.

Jorge F
  • 619
  • 1
  • 11
  • 23
2

If you have no JS manipulation to do, there's no point in using AJAX. Just submit the form to the server. You do not say what server side language you are using, but I'll assume that you are using PHP for the sake of my answer.

Your form (with submit button):

<form id="gform_29" method="get" action="form_validation.php">
    <input type="text" name="whatever">
    <input type="submit" value="Submit">
</form>

If you really need to submit via JavaScript instead of a standard submit button, you can simply call the submit() function and it'll be submitted to the URL specified in the action attribute.

$("#gform_29").submit();

And then, in the form_validation.php, you can do whatever you have to do with your form data and once you're done, you do a server side redirection like this:

header('Location: https://lets.paybygroup.com?merchant=abcd&purchase_description=Great%20rental%20for%203%20people%20with%20lake%20view.&purchase_link_url=http%3A%2F%2Fexample.com%2Fproperty&purchase_currency=CAD&purchase_cost=20&purchase_inventory_id=ESCAPE-23&purchase_name=ssss&purchase_image_url=http%3A%2F%2Fexample.com%2Fpicture.png&mixpanel=14b1230ef5970-091fdb2f9ca03e8-45574336-100200-14b1230ef5b86');

Just keep it simple. Don't use technologies that you don't really need. You can modify the URL and the method to use post if you prefer.

Gabriel
  • 2,632
  • 4
  • 25
  • 35
1

Try this code

$("#yourForm").bind('ajax:complete', function() {

         // your function


});

Update: try This

$(function() {
    $("form").submit(function(e) {
        e.preventDefault();//prevent the form from actually submitting
        window.location = 'yourpath';
    });
});
Shaminder Singh
  • 1,243
  • 2
  • 17
  • 29
  • 1
    if i prevent submitting form so how can i submit form before redirect – Sanjay Nakate Jan 27 '15 at 11:42
  • you can use ajax to post your request and then redirect on success then. – Shaminder Singh Jan 27 '15 at 11:45
  • can you tell me any example which will help me to submit form calling jquery function which currently using and then redirect? – Sanjay Nakate Jan 27 '15 at 11:48
  • i have used this like bellow my form is submitted but not redirecting – Sanjay Nakate Jan 27 '15 at 11:52
  • 1
    jQuery('.containerdddd' ).click(function() { alert("group"); jQuery('#gform_29' ).submit(); //window.open('https://lets.paybygroup.com?merchant=giftadayinc&purchase_description=Great%20rental%20for%203%20people%20with%20lake%20view.&purchase_link_url=http%3A%2F%2Fexample.com%2Fproperty&purchase_currency=CAD&purchase_cost=20&purchase_inventory_id=ESCAPE-23&purchase_name=ssss&purchase_image_url=http%3A%2F%2Fexample.com%2Fpicture.png&mixpanel=14b1230ef5970-091fdb2f9ca03e8-45574336-100200-14b1230ef5b86'); }); jQuery('#gform_29' ).bind('ajax:complete', function() { alert("submit form"); }); – Sanjay Nakate Jan 27 '15 at 11:53
  • do want post some data to server too ? – Shaminder Singh Jan 27 '15 at 11:57
  • no i just want submit a just form and then redirect – Sanjay Nakate Jan 27 '15 at 12:02