drny60365 2012-03-12 09:59
浏览 49
已采纳

Wordpress - 用户配置文件编辑的表单验证

I have added a custom field to user profiles in bbPress however I am unsure how to do form validation other than javascript. I would like to do some PHP validation however the few things I have tried didn't work.

If you fail to enter an email it will say "ERROR: Please enter an e-mail address." after you have submitted the form. I want something like that.

I have tried:

$myErrors = new WP_Error();
$myErrors->add('id_error', __('Test error.',""));

bbp_add_error( 'bbp_steamid_invalid', __( '<strong>ERROR</strong>: The ID you entered is invalid.', 'bbpress' ) );

I am not at all familiar with error handling in both WordPress and bbPress however I feel it is a must.

Any help would be must appreciated.

  • 写回答

1条回答 默认 最新

  • douxian6008 2012-03-14 21:44
    关注

    I worked it out.

    add_action( 'user_profile_update_errors', 'validate_steamid_field' );
    
    function validate_steamid_field(&$errors, $update = null, &$user  = null)
    {
        if (!preg_match("/^STEAM_[0-5]:[01]:\d+$/", $_POST['_bbp_steamid']))
        {
            $errors->add('empty_steamid', "<strong>ERROR</strong>: Please Enter a valid SteamID");
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏