I have some data that needs to be formatted via javascript on page 2 of my form. How can I trigger this javascript?
I have some data that needs to be formatted via javascript on page 2 of my form. How can I trigger this javascript?
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.
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
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";
}
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.
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.
Any ideas on this?
Alex will be responding soon, he has to take a look at what you are trying to do and see what the solution is.
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.