Validating xProfile fields – limit length
-
I am trying to limit the length of 2 xProfile fields (location {field id 2) and about {field id 3})
This is what I have come up with so far for location.
function custom_validate_xprofile_location( $data ) { global $bp; $max_location_length = 56; if ( 2 == $data->field_id ) { if ( strlen( $data->value ) > $max_location_length ) { bp_core_add_message( 'Too many characters old chap. Please try again', 'error' ); wp_redirect( $bp->loggedin_user->domain . 'profile/edit/group/1/' ); exit(); } } return $data; } add_action( 'xprofile_data_before_save', 'custom_validate_xprofile_location' );
2 questions:
1. Is this the best way of doing it?
2. How do I factor in limiting the length of the about field as well? I think this bit is harder than it looks.Note: I’ve also got
maxlength=x
in my form inputs.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Validating xProfile fields – limit length’ is closed to new replies.