最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Getting Gravity Forms AJAX Confirmation Message in Javascript Instead of Outputting - Stack Overflow

programmeradmin1浏览0评论

I have the Gravity Forms plugin setup in Wordpress, and I am using the AJAX feature on my form. I have it configured to return a Confirmation message upon submission, but I want to grab the value contained in the confirmation message in Javascript instead of having it automatically output onto the form.

I'm not sure how to get grab the Confirmation Message before it is output, or how to prevent it from being output.

It looks like the 'gform_post_render' javascript hook is called right before the message is output, but I'm not sure where to target the confirmation message value or prevent it from outputting.

Is there a way to override the confirmation message output? Or is there a better way to setup Gravity Forms to return a dynamic value through AJAX where I can then determine what to do next?

Thanks!

I have the Gravity Forms plugin setup in Wordpress, and I am using the AJAX feature on my form. I have it configured to return a Confirmation message upon submission, but I want to grab the value contained in the confirmation message in Javascript instead of having it automatically output onto the form.

I'm not sure how to get grab the Confirmation Message before it is output, or how to prevent it from being output.

It looks like the 'gform_post_render' javascript hook is called right before the message is output, but I'm not sure where to target the confirmation message value or prevent it from outputting.

Is there a way to override the confirmation message output? Or is there a better way to setup Gravity Forms to return a dynamic value through AJAX where I can then determine what to do next?

Thanks!

Share Improve this question edited Sep 28, 2015 at 20:52 Dave Hunt asked Sep 23, 2015 at 14:07 Dave HuntDave Hunt 7212 gold badges11 silver badges24 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

I ended up getting help from the Gravity Forms support team, and they remended that instead of using the included AJAX functionality, that I look into the Gravity Forms Web API, specifically the /forms/{ID}/submissions endpoint:

https://www.gravityhelp./documentation/article/web-api/#form-submissions

My solution ended up looking something like this:

$('form').submit(function(e) {

  e.preventDefault();

  // Get Form ID for submission URL //
  var formID = $(this).attr('id');
  formID = formID.replace('gform_', '');
  var formURL = '/gravityformsapi/forms/'+formID+'/submissions';

  // Get Form Input Data and Format JSON for Endpoint //
  var formArray = $(this).serializeArray();
  var formData = [];
  $.each(formArray, function(index, data) {
    var name = data['name'];
    var value = data['value'];
    formData[name] = value;
  });
  formData = $.extend({}, formData);
  var data = { input_values : formData };

  // AJAX to Submit Form //
  $.ajax({
    url: formURL,
    method: 'POST',
    data: JSON.stringify(data)
  }).done(function (data, textStatus, xhr) {
    // This is the HTML that is output as a part of the Confirmation Message //
    console.log(data.response.confirmation_message);
  });

});

This allows you to submit the form via AJAX, but then you can chose what to do with the response in the data.response.confirmation_message variable.

发布评论

评论列表(0)

  1. 暂无评论