Validation of profile form
-
Hello,
I would like to validate the profile registration form, similar to how you can validate extra fields in the registration process by hooking into registration_errors().
I tried to hook into user_profile_update_errors() in my theme options with the following code. Unfortunately nothing happens on the profile page. The form saves correctly but there is no validation if the first_name and last_name fields are left blank for example. Can you help?
I am displaying the profile form via a page template with the following code:
theme_my_login( array('instance' => '-profile', 'default_action'=>'profile', 'show_title'=>false ) );
Many thanks
Steven// Form validation for the second step of the registration process
function check_fields($errors, $update, $user) {
if ( empty( $_POST[‘first_name’] ) )
$errors->add( ’empty_first_name’, ‘ERROR: Please enter your first name.’ );
if ( empty( $_POST[‘last_name’] ) )
$errors->add( ’empty_last_name’, ‘ERROR: Please enter your last name.’ );
return $errors;
}
add_filter(‘user_profile_update_errors’, ‘check_fields’, 10, 3);
- The topic ‘Validation of profile form’ is closed to new replies.