I'm newbie on Drupal and I try to set an validation and submit the custom user registry form but I try and validation not call.
function mymodule_theme(&$existing, $type, $theme, $path){
$hooks = array();
// Make user-register.tpl.php available
$hooks['user_register_form'] = array(
'render element' => 'form',
'path' => drupal_get_path('theme', 'mymodule') . '/templates',
'template' => 'user-register',
'preprocess functions' => array('mymodule_preprocess_user_register_form'),
);
return $hooks;
}
function mymodule_preprocess_user_register_form(&$vars) {
$vars['title'] = 'Registro de candidatas';
$vars['message_welcome'] = '<p>Ingresar tu correo electrónico para iniciar este proceso. Asegúrate de tener abierto dicho correo para recibir las notificaciones y realizar de manera inmediata las indicaciones que recibas.</p>';
//Shortens the form variable name for easier access
$form = $vars['form'];
$form['account']['mail']['#attributes'] = array(
'placeholder' => 'Escribe tu correo electrónico',
'class' => array(
'mymodule-form-email-input'
)
);
$form['account']['mail']['#title_display'] = 'invisible';
$form['account']['mail']['#description'] = '';
$form['account']['pass']['pass1']['#title_display'] = 'invisible';
$form['account']['pass']['pass1']['#attributes'] = array(
'placeholder' => 'Escribe una contraseña',
'class' => array(
'mymodule-form-email-input'
)
);
$form['account']['pass']['pass2']['#title_display'] = 'invisible';
$form['account']['pass']['pass2']['#attributes'] = array(
'placeholder' => 'Vuelve a escribir contraseña',
'class' => array(
'mymodule-form-email-input'
)
);
$vars['mail'] = render($form['account']['mail']);
$vars['pass'] = render($form['account']['pass']);
$vars['captcha'] = render($form['captcha']);
}
function mymodule_user_register_form_alter(&$form, &$form_state, $form_id) {
$form['account']['mail']['#field_prefix'] = '';
$form['#validate'][] = 'mymodule_user_register_form_validate';
}
function mymodule_user_register_form_validate(&$form, &$form_state) {
drupal_set_message(t('AN ERROR OCURED'));
if ($form_state['values']['mail'] !== '') {
form_set_error('mail', t('Escribe un correo electrónico'));
} else {
if(valid_email_address($form_state['values']['mail'])) {
form_set_error('mail', t('Email invalido'));
}
}
if ($form_state['values']['pass']['pass1'] !== '') {
form_set_error('mail', t('Escribe una contraseña'));
}
if ($form_state['values']['pass']['pass2'] !== '') {
form_set_error('mail', t('Confirma tu contraseña'));
}
if ($form_state['values']['pass']['pass1'] !== $form_state['values']['pass']['pass2']) {
form_set_error('mail', t('La contraseñas no coinciden'));
}
if (!$form_state['values']['sendgift']) {
form_set_error(NULL, '', TRUE);
drupal_get_messages();
}
}
Something I have wrong? I look on documentation and I found few details on registration. I read about hook_form_alter() and hook_preprocess_form() but it's confusing to me.
Thanks