Wordpress - validate a form to edit a user profile

I've added a custom field to user profiles in bbPress, but I'm not sure how to do non-javascript form validation. I would like to do some PHP validation, however some of the things I've tried don't work.

If you fail to enter the email, it will say, "ERROR: Please enter your email address." after you have submitted the form. I want something like this.

I 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'm not entirely familiar with error handling in both WordPress and bbPress, but I believe it is necessary.

Any help should be appreciated.


source to share

1 answer

I worked.

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");




All Articles