Reputation: 403
When i call Gravity Form in my theme's functions.php using ajax the form fields are disabled. Any solutions will help me a lot.
add_action('wp_head', 'mytheme_fn');
add_action('wp_ajax_mythem_load_gravityform', 'mythem_load_gravityform_call');
function mytheme_fn(){
?>
<script>
jQuery(document).ready(function () {
var data = {
action: 'mythem_load_gravityform'
};
jQuery.post(
ajaxurl,
data
).success(function (data) {
jQuery('.gformholder').html(data);
});
});
</script> <?php }
function mythem_load_gravityform_call(){
gravity_form(1, false, false, false, null,false);
exit;
}
Thank you in advance.
Upvotes: 0
Views: 1844
Reputation: 139
From a Gravity Forms Support Specialist:
"The issue is caused by GF's implementation of the form rendering logic. They check whether is_admin() returns true (and it does when you call ajax on Wordpress) and if so, they render it like you were in admin."
We have made a number of changes in Gravity Forms 1.9 so and is_admin check is no longer performed when loading forms and fields, which means forms and fields can now be loaded via AJAX and they will render correctly.
Gravity Forms 1.9 has just been released: http://www.gravityhelp.com/gravity-forms-v1-9-released/
Regarding the enhanced ui, this is powered by the chosen.js script and when you make change to the underlying select element you will need to trigger an update of the chosen interface: http://harvesthq.github.io/chosen/options.html#triggerable-events
Upvotes: 1
Reputation: 21
The issue is caused by GF's implementation of the form rendering logic. They check whether is_admin() returns true (and it does when you call ajax on Wordpress) and if so, they render it like you were in admin.
I can think of two solutions here:
1) dummy endpoint create a dummy page with template file without head or foot, just a plain gravity_form(...); Then call this url from your js.
2) plugin create a plugin, which registers custom query var (using query_vars filter), and then process the query variable by showing the gravity_form(...) output.
Upvotes: 0