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.

Simple AJAX Test

  1. gimlet

    I've got a very simple JSON service running on my site where you ask /service?foo=bar and get back a response of {"response":"Yes"} or {"response":"No"}.

    I'd like an input field that allows my users to specify a value for 'foo' and a button that makes the request to /service with the value, and displays the response to the user. If the response is Yes, the value for 'foo' needs to be validated and the user allowed to submit the form.

    Is this possible with hooks and if so, how do I set it up? Thanks!

    Posted 7 years ago on Saturday December 15, 2012 | Permalink
  2. I think you will have to use the gform_validation hook to accept the input from the user, query your JSON service, then compare the result and return a validation error if the response is not Yes.

    Posted 7 years ago on Tuesday December 18, 2012 | Permalink
  3. gimlet

    Thanks, that does appear to work. I was hoping for a more elegant solution where I don't need to submit the form prior to validating. An ability to add an extra 'Validate this field' button would be ideal. If there's no chance of that, let me know and I'll stick to the validation after submission approach.

    Posted 7 years ago on Wednesday December 19, 2012 | Permalink
  4. If you want to do the validation before the form is submitted, you would need to add some jQuery or JavaScript validation. Gravity Forms validation will only happen after the form is submitted. There are quite a few discussions online for jQuery validation:

    Posted 7 years ago on Thursday December 20, 2012 | Permalink