• Resolved hexagondigital

    (@hexagondigital)


    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)
  • Plugin Support Kris – WPMU DEV Support

    (@wpmudevsupport13)

    Hi @hexagondigital

    I hope you are doing well today.

    Could you export all your forms, upload it to google drive or dropbox and share a link in your next reply?

    This will give us a better light on your code.

    Kind Regards,
    Kris

    Thread Starter hexagondigital

    (@hexagondigital)

    Hi Kris,

    No problem at all. You can find the forms here: https://drive.google.com/drive/folders/1DtYFw5t7H-nZIZemJaGa3OZI1loyYdNm?usp=sharing

    As it stands, the one I have been testing in an attempt to resolve is the ‘Contact Us’ form. But the issue does exist on the other forms.

    Thanks

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @hexagondigital

    Thanks for sharing the form!

    However, I noticed something in your code.

    Is the code that you are actually using having this line?

    var_dump($result);

    If so, it shouldn’t be used like this. If you need to see the result data use something like this instead of this line

    error_log( print_r( $result, true ) );

    while having WordPress debugging enabled with option to write to the /wp-content/debug.log file. You can set it by adding following lines to the “wp-config.php” file right above the “/* that’s all, stop editing */” line:

    define( 'WP_DEBUG', true );
    define( 'WP_DEBUG_DISPLAY', false );
    define( 'WP_DEBUG_LOG', true );

    This way your code will not print out the data on the page (which in case of some hooks may possibly cause conflicts by “messing up” data) and instead write it into the “/wp-content/debug.log” file.

    Give it a try, please, and if it doesn’t solve the issue, let us know and we’ll continue checking it.

    Best regards,
    Adam

    Thread Starter hexagondigital

    (@hexagondigital)

    Hi Adam,

    That’s fixed it, thanks. Your help is much appreciated!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Error submitting form with custom php function’ is closed to new replies.