I am trying to validate my registration form in a custom module but even ‘allowed’ chars is returning the error message (Loggitobbogan is also installed). Am I making a rookie mistake in my script, please?
/**
* Implements hook_form_FORM_ID_alter
*/
function myApp_registration_form_user_register_form_alter(&$form, &$form_state, $form_id) {
$form['locale']['#access'] = ($form['#user_category'] == 'account' || ($form['#user_category'] == 'register'));
$form['privacy'] = array(
'#type' => 'checkbox',
'#required' => TRUE,
'#title' => t('Please accept ') . ' ' . l(t('Terms of Use and Privacy'), t('terms-use-and-privacy')),
'#weight' => 10
);
$form['field_full_name']['und'][0]['value']['#attributes']['placeholder'] = t('Chose a user name');
$form['account']['mail']['#attributes']['placeholder'] = t('Your email address');
// Change the value of the submit button
$form['actions']['submit']['#value'] = t('Register');
//look for illegal chars in field_full_name
$form['#validate'][] = 'myApp_fullname_registration_form_validate';
}
//function to look for illegal chars in field_full_name
function myApp_fullname_registration_form_validate(&$form, &$form_state) {
$fullName = $form_state['values']['field_full_name']['und'][0];
if (!preg_match( '/[^A-Z|a-z|0-9]*/', $fullName )) {
form_set_error('field_full_name', t('Illegal chars used?!'));
}
}
Any guidance, advice, pointers are gratefully accepted! Thank you.
This is the whole relevant section from myApp_registration.module file, where I can change placeholder text successfully, and where I believe I could add my form_validation script. It is cut and pasted and works fine, except the new form_validate function.
It is Drupal 7.