I wanted to add some extra fields to obtain extra user info which I have added easily that looks like.
The example code for a single form field, I added:
add_action( 'show_user_profile', 'extra_user_profile_fields' );
add_action( 'edit_user_profile', 'extra_user_profile_fields' );
function extra_user_profile_fields( $user ) { ?>
<table class="form-table">
<tr>
<th><label for="address"><?php _e("Address"); ?><span class="description"> (required)</span></label></th>
<td>
<input type="text" name="address" id="address" value="<?php echo esc_attr( get_the_author_meta( 'address', $user->ID ) ); ?>" class="regular-text" required/><br />
<span class="description"><?php _e("Please enter your address."); ?></span>
</td>
</tr>
add_action( 'personal_options_update', 'save_extra_user_profile_fields' );
add_action( 'edit_user_profile_update', 'save_extra_user_profile_fields' );
function save_extra_user_profile_fields( $user_id ) {
update_user_meta( $user_id, 'address', $_POST['address'] ); }
I want to validate the user entered data, like if left empty or invalid address format. I have all validation patterns to be matched for format. I have implemented jquery validation but want to make sure if user has disabled javascript, validate it by server side too. At what point should I add validation functions before adding/updating user meta, so if anything is missing user should be redirected back to profile page with an error otherwise to another page?
Thanks