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.

Running javascript on "next page" click

  1. I have some data that needs to be formatted via javascript on page 2 of my form. How can I trigger this javascript?

    Posted 14 years ago on Thursday November 18, 2010 | Permalink
  2. Alex already touched on this here:

    http://forum.gravityhelp.com/topic/bug-gform_post_submission-called-on-next-page#post-12892

    We will be adding a hook that fires after each page. It's not currently available.

    Posted 14 years ago on Thursday November 18, 2010 | Permalink
  3. Oh, I figured that'd be all PHP based.

    Is there anyway I can hack this in right now? Hints on where I can inject my needs as a stop gap measure until this feature is complete? This form is time sensitive.

    edit: looks like I can hack line 415 in form_display.php

    Posted 14 years ago on Thursday November 18, 2010 | Permalink
  4. Gravity Forms v1.5 Beta 2 was released earlier today and contains a hook that fires when you click back or forward.

    Here is an example:

    add_action("gform_post_paging", "page_changed", 10, 3);
    function page_changed($form, $source_page, $target_page){
        echo "Page changed from $source_page to $target_page";
    }
    Posted 14 years ago on Thursday November 18, 2010 | Permalink
  5. In this case, I'd have to do inline javascript though correct?

    i.e.

    add_action("gform_post_paging", "page_changed", 10, 3);
    function page_changed($form, $source_page, $target_page){
        echo '<script type="text/javascript">alert("you've done it!");</script>';
    }

    I was hoping for a pure javascript hook.

    Here is my hacky implementation, hardcoded to a form and page

    $onclick = "onclick='jQuery(\"#gform_target_page_number_{$form_id}\").val(\"{$target_page_number}\"); jQuery(\"#gform_{$form_id}\").trigger(\"submit\",[true]); if ({$form_id}==3 && {$target_page_number}==2) { setTimeout(\"do_it()\", 1000); }'";

    My programming teacher would probably roll his eyes at this solution but sometimes you've just gotta do the dirty dirty. You'll notice I had to set a timeout to a second so it doesn't fire the function until after the HTML in injected. This however causes a slight flash in the display.

    Posted 14 years ago on Thursday November 18, 2010 | Permalink
  6. I can't seem to get new setTimeout working with this hook. Though, the only reason I need setTimeout is because it appears the javascript is running before the elements on the page are drawn. The reason this is relevant is because I'm trying to skin the form with jquery ui.

    echo '<script type="text/javascript">setTimeout("alert(\'hello\')",1250);</script>';

    it's worth noting the following works:
    echo '<script type="text/javascript">alert(\'hello\');</script>';

    However, I cannot skin the elements this way.

    Posted 14 years ago on Monday December 6, 2010 | Permalink
  7. Any ideas on this?

    Posted 14 years ago on Thursday December 9, 2010 | Permalink
  8. Alex will be responding soon, he has to take a look at what you are trying to do and see what the solution is.

    Posted 14 years ago on Thursday December 9, 2010 | Permalink
  9. A Javascript hook makes complete sense. Send me an email to alex@rocketgenius.com and I will send you our latest version with that hook.

    Posted 14 years ago on Friday December 10, 2010 | Permalink