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.

Donation Form

  1. BIGLIFE
    Member

    I am creating a Donation Form that links to an online credit card processor. I need the form to send the donor to a new page where either a confirmation message is displayed or an error message based on the returned fault code (invalid credit card number, decline, etc.) by the online processor. If the online processor sends a fault I would like to display/explain the error as well as have a link back to the donation page with the previous input fields auto populated based on the previously submitted data.

    Currently I am using the "gform_post_submission" function to submit the data to the online processor but the entry is still being submitted and thus a notification email is being sent (to admin) as well as a confirmation message/page/redirect is happening based on form settings. How might I go about this as I'm a bit lost.

    Posted 12 years ago on Tuesday August 23, 2011 | Permalink
  2. gform_post_submission is triggered after the form is submitted and the entry data is stored. It happens too late in the form submission process to be used for what you are trying to do.

    You would have to use the gform_pre_submission hook which is triggered after validation but before entry creation and notifications are sent. Documentation for it is here:

    http://www.gravityhelp.com/documentation/page/Gform_pre_submission

    You may also need to use the gform_validation hook for doing any custom field validation and triggering a validation error.

    Posted 12 years ago on Tuesday August 23, 2011 | Permalink
  3. BIGLIFE
    Member

    If I am correct then I would not have access to the entry data using the "gform_pre_submission"? I need this data to process the online donation transaction. The problem it that I need to convey to the donor whether or not their gift was accepted or denied and if denied then display the form again to have them fix the incorrect data.

    Just thinking here but would it work to disable the notifications (gform_disable_user_notification) and post (gform_disable_post_creation) for this form until the online transaction(donation) is accepted and then submit/enable post and notification?

    Posted 12 years ago on Tuesday August 23, 2011 | Permalink
  4. Correct. The gform_pre_submission doesn't have access to the entry data because the entry data doesn't exist yet. It has access to the FORM object which is all of the form data. So you would use the gform_pre_submission hook as well as the gform_validation hook for any validation to return validation errors.

    Posted 12 years ago on Tuesday August 23, 2011 | Permalink
  5. BIGLIFE
    Member

    I see how this would allow me to validate data before it is sent but what would I need to do if I desired to send this data to a third party (processing merchant) and then based on their response (accept/deny) I would either show a confirmation page or re-display the form with text stating the error and auto-populated fields with previously submitted data. I would also like to get a response from third party (processing merchant) before a notification is sent (obviously would not send notification/confirmation if denied) as well as the submitted data posted to the WP Gravity Form database.

    Posted 12 years ago on Tuesday August 23, 2011 | Permalink
  6. What you need to do is use the gform_validation_hook. The entry is not going to be available in that hook, but you can access all submitted values using the $_POST global variable.
    In that hook, you would send your request to the third party and set the $validation_result variable accordingly. If the payment fails, you would mark the submission as failed and that will reload the form with all fields pre-populated and an error message will be displayed.
    If the payment is successful, you would mark the submission as successful and that would cause the entry to be created, the confirmation to be displayed and the notifications to go out. The following two pages have a pretty good explanation on how to use the gform_validation hook and should get you on the right track.
    http://www.gravityhelp.com/documentation/page/Gform_validation
    and
    http://www.gravityhelp.com/documentation/page/Using_the_Gravity_Forms_%22gform_validation%22_Hook

    Posted 12 years ago on Tuesday August 30, 2011 | Permalink