Forminator to API Handle Errors
-
Hi there,
I am usingforminator_custom_form_submit_before_set_fieldsto send the form data to API. Here is a simple example.add_action( 'forminator_custom_form_submit_before_set_fields', function ($entry, $form_id, $form_data_array) { if ($form_id != 12345) { return; } // API key & Endpoint $endpoint = 'https://endpoint.com/api'; $body = [ 'name' => 'Satrya', 'email' => '[email protected]', ]; $body = wp_json_encode($body); // Send the data to the API $response = wp_remote_post($endpoint, [ 'body' => $body, 'headers' => [ 'Content-Type' => 'application/json', ], 'timeout' => 60, 'redirection' => 5, 'blocking' => true, 'httpversion' => '1.0', 'data_format' => 'body', ]); if (is_wp_error($response)) { // Handle error } else { // Handle success } }, 10, 3 );If Error or something when wrong
1. I’d like to display a custom message.
2. Stop form submitAppreciate for any help. Thanks!
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
The topic ‘Forminator to API Handle Errors’ is closed to new replies.