Run forminator_custom_form_submit_errors hook only for submit?
-
Hi there,
So, I am usingforminator_custom_form_submit_errorshook to send the form data to a custom endpoint. But, I just realized it also run when user click on Save Draft button. Is there a way to prevent this? I just want to run the function when user click the submit button. Here’s the sample code./** * Send the form data to API */ add_action( 'forminator_custom_form_submit_errors', function ($submit_errors, $form_id, $field_data_array) { if ($form_id != FORMID) { return $submit_errors; } // API key & Endpoint $endpoint = 'ENDPOINT_URL'; // Form data $data = array_column($field_data_array, 'value', 'name'); $body = [ 'name' => $data['text-1'] ? esc_attr($data['text-1']) : '', ]; // JSON encode data $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 ($response['response']['code'] !== 200) { $submit_errors[]['submit'] = 'API Error!'; $GLOBALS['api_error'] = true; // for custom message. } else { $GLOBALS['api_error'] = false; } return $submit_errors; }, 15, 3 );Thank you.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘Run forminator_custom_form_submit_errors hook only for submit?’ is closed to new replies.