[Science, Technology, Engineering, Arts and Maths]

Buddypress add validation to custom field

So you need to validate a custom registration field in buddypress. You will want to be looking at the hook bp_signup_validate. The following code can be added to your custom functions.php file.

/** /
* If the year of birth is too long - generate an error
*
* @global type $bp
*/
function innovage_validate_user_registration()
{
global $bp;
$year_of_birth = $_POST['field_2'];
if (empty($year_of_birth) || $year_of_birth == '' || strlen($year_of_birth)<4 || !is_numeric($year_of_birth))
{$bp->signup->errors['field_2'] = __('This field must be a 4 digit year (e.g. 1985)','buddypress');
}
return;
}
add_action ('bp_signup_validate','innovage_validate_user_registration');

Leave a Reply

Your email address will not be published. Required fields are marked *