Custom validations on user profile form

Sometimes you want to have some more fields on your user profile form. This is quite easy to setup. However Drupal will not validate these fields out of the box.
So we need to write our own validation functions and tell Drupal that it exists.

Here is a simple example:
<?php
function example_user_profile_form_alter($form_id, &$form, &$form_state){
  if($form_id == 'user_profile_form'){
   $form['#validate'] = 'example_user_profile_custom_validate';
 }

}

function example_user_profile_custom_validate(&$form, &$form_state){
  // Do your validations here

}

?>

Add new comment