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");
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染