PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Redirect on error or success

  1. I have a form that is in a small space in my design. If a user submits the form and forgets a field I need to have it redirect to a new page instead of replacing the form with the error message (there is not enough room in the design for the message).

    Alternatively I would like the confirmation and error to appear in a modal box preferably without a page refresh.

    Is any of this possible?

    Cheers,

    Eric

    Posted 14 years ago on Friday October 8, 2010 | Permalink
  2. Bump as I am still looking for the workaround. Cheers.

    Posted 14 years ago on Monday October 11, 2010 | Permalink
  3. The only thing you could try doing is using a hook to hardcode the form action and point it to a page that also has the form embedded on it. The filter you would use is the gform_form_tag filter.

    Here is an example:

    <?php
    add_filter("gform_form_tag", "form_tag", 10, 2);
    function form_tag($form_tag, $form){
    $form_tag = preg_replace("|action='(.*?)'|", "action='custom_handler.php'", $form_tag);
    return $form_tag;
    }
    ?>

    That would change the form action to custom_handler.php... in your case you would probably want it to be something like this:

    http://mydomain.com/my/page

    This is just a suggestion. Gravity Forms doesn't do what you are asking by default so no guarantees this would accomplish your goal.

    Posted 14 years ago on Monday October 11, 2010 | Permalink
  4. I found a good workaround that I wanted to share. Instead of doing the change in GF I just detect if the error message is there and if it is I redirect via javascript/jquery. Here is the code:

    /* Catalog goto page on error */
    	if (jQuery("#catalogFlyout .validation_error").length){
        // do something here
        document.location.href = '/form-error';
    }
    Posted 14 years ago on Tuesday October 12, 2010 | Permalink
  5. Is there a work around for Redirecting on Errors yet? I am placing a gravity form in a header with 110px height and would like to redirect on errors. I have tried to use the javascript eCurtis posted but was not sure it I can call the Javascript from the header.php file by adding a call to a js file?
    Something like <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/formerror.js"></script>

    Thanks for any help!

    Posted 12 years ago on Saturday March 24, 2012 | Permalink
  6. I think I got it figured out. I had to make a few modifications to get it working. I decided not to redirect but to alert with javascript then refresh. I am thinking I would like to just clear the form rather then refresh, but I am using css to hide the Validation error container and messages and without refreshing the page they do not show.

    jQuery(document).ready(function(){
        if(jQuery("body #gform_wrapper_2 div.validation_error").length != 0){
    
            // code that should be run if the validation error exists goes here
      alert("First Name, Last Name and Email must be filled out");
      window.location.reload()
          }
    });
    Posted 12 years ago on Saturday March 24, 2012 | Permalink
  7. Gaslight
    Member

    I had a similar issue and tried to use the solution proposed by Carl

    however it doesn't work for me... I have a registration form (the form ID is 2)

    I placed this code in my functions

    function sg_regform_redirect( $form_tag, $form ) {
    
        $form = 2;
        $form_tag = preg_replace( '|action="(.*?)"|', 'action="' get_bloginfo( 'url' ) . '/register' . '"', $form_tag);
        return $form_tag;
    
    }
    add_filter( 'gform_form_tag', 'sg_regform_redirect', 10, 2);

    I tested the form and it doesn't redirect to the page indicated, it just runs as usual. despite there are errors or not

    I also tried to hardcode the page to redirect the form action to, but no difference

    maybe I'm handling the $form value incorrectly? I only want this filter to apply on a specific form with ID = 2.

    can you help me?

    thank you

    Posted 12 years ago on Saturday July 28, 2012 | Permalink
  8. Gaslight
    Member

    ps - of course the target page contains the same form as the form I want to redirect there (however, mind that the form I want to filter is embedded into a modal window found in the header of my theme - the reason why I need error messages or validation messages appear in a new page is that I can't use ajax on that modal window otherwise some other forms will be broken)

    Posted 12 years ago on Saturday July 28, 2012 | Permalink
  9. luxerman
    Member

    curtis, I entered your code into the html but nothing happens. is there other coding I have to add? thanks

    Posted 11 years ago on Tuesday February 5, 2013 | Permalink
  10. @luxerman, what are you trying to accomplish exactly, and on what page (URL where the form is embedded, please.)

    Posted 11 years ago on Tuesday February 5, 2013 | Permalink
  11. luxerman
    Member

    I forgot to add the "</SCRIPT>" tags... it works now :)

    Posted 11 years ago on Tuesday February 5, 2013 | Permalink
  12. That would do it :-)

    Thanks for updating the topic.

    Posted 11 years ago on Tuesday February 5, 2013 | Permalink