Active
Project:
Ajax Forms Validation
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
11 Jun 2012 at 13:04 UTC
Updated:
11 Jun 2012 at 13:04 UTC
Hi,
I'm trying to validate an input field after form submission but the ajax callback seems not to look after my condition. Here is the code:
/**
* Perform alterations before a form is rendered.
*/
function MY_MODULE_domaincheck_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'user_register_form') {
$form['account']['mail'] = array(
'#type' => 'textfield',
'#title' => 'E-Mail',
'#maxlength' => 254,
'#description' => '',
'#required' => TRUE,
'#default_value' => '',
'#ajax' => array(
'callback' => 'ajax_email_domain_callback',
'wrapper' => 'my_wrapper',
'effect' => 'fade',
'event' => 'submit',
),
'#prefix' => '<div id="my_wrapper">',
'#suffix' => '</div>',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => 'Registrieren',
'#ajax' => array(
'callback' => 'ajax_email_domain_callback',
'wrapper' => 'my_wrapper',
'effect' => 'fade',
),
);
// THIS PART IS NOT WORKING AFTER THE FORM HAS BEEN SUBMITTED
if (!empty($form_state['values'])) {
if (MY CONDITION) {
form_set_error('', 'MY ERROR MESSAGE');
}
}
return $form;
}
}
function ajax_email_domain_callback($form, $form_state) {
return $form['account']['mail'];
}