Came across a tricksy little issue recently trying to submit a Gravity Form that needed to be loaded dynamically onto a popup (used the WP Popup Maker + Remote Content plugins for that)
So here’s the fix… (all code can go in child theme functions.php)
First off you might need to enqueue the Gravity Form scripts on the page for the relevant form ID (#3 in this case):
e.g.
add_action( ‘genesis_after_header’ , ‘add_gform_scripts’ );
function add_gform_scripts() {
gravity_form_enqueue_scripts( 3, true);
}
Then you add the relevant popup maker stuff. Won’t document all that here though..
You should set ajax to true in the shortcode that goes into the popup.
Now for the crucial bit! Because the form in the popup has been dynamically loaded instead of being associated with a post/page you need to override the action for the ajax submit to work. Here’s how:
add_filter(“gform_form_tag”, “form_action_override”, 10, 2);
function form_action_override($form_tag, $form){
if ( $form[‘id’] == 3 ) {
$form_tag = preg_replace(“|action='(.*?)’|”, “action=’/'”, $form_tag);
}
return $form_tag;
}
Now when the form submits you get the confirmation message loading into the popup. Which should make you happy!