user12457660
user12457660

Reputation: 19

Redirect CF7 form depending on API response?

I'm trying to figure out a way to redircet a user after submission of a form and receiving a certain response from the server.

The response logic is server side and I'm successfully getting and checking the response conditional.

From here I am unsure of how to pass that variable on to the recommended JS hook way of setting the window location I.E;

$(Form).on('wpcf7mailsent',
       function( event ) {
               location = Url;
       }
);

Firstly I am not checking the response object with JS as I don't know how, my ideal solution would be to check the response object for a certain property in the wpcf7mailsent hook.

The response is currently checked with php, at which point I can change the plaintext response message displayed and I think that's about it.

Does anyone have any advice on this?

Upvotes: 0

Views: 342

Answers (1)

user12457660
user12457660

Reputation: 19

My soloution was to use the function of WPCF7 called add_result_props();

In the wpcf7_before_send_mail you can set a new property on the $submission param like so

$submission->add_result_props( array( api_data => response_body ) );

You could also just set key values in a conditional with the same method.

 $submission->add_result_props( array( key => value ) );

I got the answer from this stack overflow post: https://stackoverflow.com/a/70056314/12457660

Upvotes: 1

Related Questions