WordPress Caldera Forms show error message on validation

Viewed 613

I am trying to create a custom add-on for Caldera Forms. So basically I am creating a processor for Caldera Forms. In that add-on when someone tries to submit the form it should show a custom error. So for that I have done my code like this

add_filter( 'caldera_forms_get_form_processors', 'wpcfmu_register_processor' );

function wpcfmu_register_processor() {
    $processors['wp_cf_mu_integration'] = array(
        "name"              =>  __('Custom Integration'),
        "description"       =>  __("Custom Plugin"),
        "author"            =>  'test',
        "pre_processor"    =>  'wpcfmu_pre_process',
    );

    return $processors;
}

function wpcfmu_pre_process($config, $form, $process_id) {
    $error = 'something happened wrong';
    return array(
        'note' => $error,
        'type' => 'error'
    );
}

But here no such is showing at all. I have tried to change the code but anyhow its showing the success message. Can someone tell me what going wrong here?

Any help and suggestion will be really appreciable.

1 Answers

so far I have understood that you're making a little syntax error that's why it is returning neither form value nor errors.

function wpcfmu_register_processor() {
    $processors['wp_cf_mu_integration'] = array(
        'name' => __('Custom Integration'),
        'description' => __('Custom Plugin'),
        'author' => 'test',
        'pre_processor' => 'wpcfmu_pre_process'
    );
}

function wpcfmu_pre_process($config, $form, $process_id) {
    $error = 'some happened wrong';
    return array(
        'error' => $error,
        'type' => 'error'
    );
}

As you can see you had some quotation issues, you sometimes have used single quote and sometimes double quote. You have to be consistent about quotes in PHP. If your problem isn't solved then comment under it we will figure it out.

UPDATE: Have you tried to analyze the error log file right when you submit the form? If there is an error then show me.

If there isn't any error then check your error reporting is on or not.

If nothing fixed after all this then

//find and return error
if( is_wp_error( $response ) ){
    $error = $response->get_error_message();
}elseif ( isset( $response[ 'error' ]) ){
    $error =  $response[ 'error' ];
}else{
    $error = 'Something bad happened';
}

Then you put your error function

function wpcfmu_pre_process($config, $form, $process_id) {
    $error = 'some happened wrong';
    return array(
        'error' => $error,
        'type' => 'error'
    );
}

Hopefully, you will get an error to resolve. If you didn't get the error, then comment again. We will see.

Related