Error submitting form with custom php function
-
Hi,
I have a number of forms on a website that get submitted via php to an outside service. As it stands, when submitting a form, the form is correctly submitted via php and is also collected in the forminator submissions, however on the front end, the user receives a message saying ‘An error occurred while processing the form. Please try again’, which suggests to the user that the form submission has not worked.My php code is as follows:
add_action('forminator_custom_form_submit_before_set_fields', function($entry, $form_id, $field_data_array) { if( '955' !== $form_id && '1010' !== $form_id && '1021' !== $form_id && '1316' !== $form_id && '1445' !== $form_id && '1609' !== $form_id ) { return; } $post_data = array_column( $field_data_array, 'value', 'name' ); $url = 'https://www.hashemian.com/tools/form-post-tester.php/testme'; $data = array('First Name' => $post_data[ 'name-1' ] ?? 'none', 'Last Name' => $post_data[ 'name-2' ] ?? 'none', 'Email' => $post_data[ 'email-1' ] ?? 'none', 'Phone' => $post_data[ 'phone-1' ] ?? 'none', 'Company' => $post_data[ 'text-1' ] ?? 'none', 'Postcode' => $post_data[ 'text-2' ] ?? 'none', 'Message' => $post_data[ 'textarea-1' ] ?? 'none', 'Type' => $post_data[ 'hidden-1' ] ?? 'none', 'Site' => $post_data[ 'hidden-2' ] ?? 'none', 'Location' => $post_data[ 'hidden-3' ] ?? 'none', 'Engineer' => $post_data[ 'hidden-4' ] ?? 'none', 'gdpr_acceptance' => $post_data[ 'consent-1' ] ?? 'none'); $options = array( 'http' => array( 'header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => http_build_query($data) ) ); $context = stream_context_create($options); $result = file_get_contents($url, false, $context); var_dump($result); }, 10, 3);
Any help would be greatly appreciated. Thank you.
The page I need help with: [log in to see the link]
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Error submitting form with custom php function’ is closed to new replies.