Validate extra user fields in profile page
-
Days and days spent trying to solve this mistake but seems to be no solution…
In my function.php I add some user extra fields:function add_additional_user_meta( $profileuser ) { // here my input fields <input type="text" id="test" name="test" value="<?php echo esc_attr( $profileuser->test ); ?>" /> } add_action('show_user_profile', 'add_additional_user_meta'); add_action('edit_user_profile', 'add_additional_user_meta');Than I add the action hook to save them:
function save_additional_user_meta( $user_id ) { // here I save fields update_user_meta( $user_id, 'test', $_POST['test'] ); } add_action( 'personal_options_update', 'save_additional_user_meta' ); add_action( 'edit_user_profile_update', 'save_additional_user_meta' );Ok! That’s work!
But.. What about validation?I add another action hook for validate and display error message
function check_fields($errors, $update, $user){ // here make some validation if ( empty( $_POST['test'] ) ) { $errors->add( 'empty_test', __( '<strong>ERROR</strong>: You must write the test field' ) ); } } add_filter('user_profile_update_errors', 'check_fields', 10, 3);The error message work but the field is saved however!
Where is the mistake?Hope someone can help me!
Thanks
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
The topic ‘Validate extra user fields in profile page’ is closed to new replies.