How to show Error Message after submission

Hello!
We use the gform_after_submission hook to send the form data to a different server by CURL request. We need an error message, when the server does not respond in time. How can we achieve this? Actually the error from CURL is shown right now, but still the Confirmation Message by GravityForms is shown after that.

A workaround would be to disable the confirmation message and echo the success message within the after_submission hook, but this way editors couldn’t change the message, so this is not ideal…

Note: It’s NOT about validation here, it’s about an error message that could bubble up from the after submission-hook.

Thanks in advance!

Instead of gform_after_submission, try using something that happens before confirmation, like gform_pre_submission or gform_validation.

You can find a good reference here for one to choose rather than something that happens too late:

https://gravitywiz.com/gravity-forms-hook-reference/#form-submission-successful

Okay, and is it possible to output the response of my CURL request as Confirmation or change the Confirmation message from gforms depending on the response?

If you are using gform_after_submission, no, because that happens after gform_confirmation. You need to run your cURL request before confirmation in order to use the results in that confirmation.

If you look at this awesome reference, you can find a good place to run your code, so the result is available BEFORE confirmation:

https://gravitywiz.com/gravity-forms-hook-reference/#form-submission-successful

Yes, i will use a hook that does the request before confirmation, however could you give me a hint whats best practise to influence the confirmation from within a hook that runs before? Your link gives me the sequence of how the hooks run through, but it says “This scenario uses the default confirmation and the default notification.” and does not give me a hint on how to manipulate this by PHP.

My thought would be to make the standard confirmation an error, but when the request worked, i’ll change the confirmation to a success one:

if (request answer != 0 ) //Meaning NOT OK
nothing changes, standard error_confirmation stays
else (meaning 0, success)
add_filter( ` `'gform_confirmation'` `, ` `'success_confirmation'` `, 10, 4 );