php - WordPress Caldera Forms 在验证时显示错误消息

标签 php wordpress

我正在尝试为 Caldera Forms 创建自定义附加组件。所以基本上我正在为 Caldera Forms 创建一个处理器。在该附加组件中,当有人尝试提交表单时,它应该显示自定义错误。所以为此我做了这样的代码

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'
    );
}

但这里根本没有这样的表现。我试图更改代码,但无论如何它显示成功消息。谁能告诉我这里出了什么问题?

任何帮助和建议都将不胜感激。

最佳答案

到目前为止,我了解到您犯了一点语法错误,这就是它既不返回表单值也不返回错误的原因。

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'
    );
}

如您所见,您遇到了一些引用问题,您有时使用单引号,有时使用双引号。您必须对 PHP 中的引号保持一致。如果您的问题没有解决,请在问题下方发表评论,我们会解决的。

更新: 您是否尝试过在提交表单时立即分析错误日志文件?如果有错误,请告诉我。

如果没有任何错误,请检查您的错误报告是否打开。

如果这一切都没有解决,那么

//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';
}

然后你把你的错误函数

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

希望您能解决一个错误。如果您没有收到错误,请再次评论。我们拭目以待。

关于php - WordPress Caldera Forms 在验证时显示错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56445329/

相关文章:

PHP MYSQL 连接到用户名 session

php - WordPress 自定义数据库查询

mysql - 如何将 mysql 查询执行到 cf7 按钮操作中

php - wordpress 提取媒体 url

php - 用php实现倒数计时器

PHP 优化 : Fetching from database

javascript - 普通 JS : make 80% width element 100% IF contains an image

javascript - 如何使用仪表板在WordPress中插入iframe

php - WordPress wp-load.php

javascript - 如何在 laravel TableView Blade 中显示 JSON 中的指定对象值