Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I am trying to apply clientside validation on a form which is being displayed in quicktabs But on submitting the form am getting the whole ajax callback and nothing else.
The form contains a title field and submit.
The validations work on this form everywhere else, but not when i use it in a quicktab. Even when i enter validated data, the form does not submit but redirects and displays the ajax callback.
Code for form is as below.
function cdin_story_pre_create_form($form, &$form_state) {
$lang = 'und';
$form['heading'] = array(
'#type' => 'markup',
'#markup' => '<h3>Create a new Story</h3>',
);
// Attaching project_type field.
$node = new stdClass();
$node->type = "story";
field_attach_form('node', $node, $form, $form_state, NULL, array('field_name' => 'title_field'));
$form['title_field'][$lang][0]['value']['#required'] = TRUE;
$form['title_field'][$lang][0]['value']['#rules'] = array(
array('rule' => 'regexp[/^[a-zA-Z0-9 ]*$/]', 'error' => t('Invalid Title Format.')),
);
// Form submit button.
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
'#weight' => 100,
);
return $form;
}
Comments
Comment #1
aaghran CreditAttribution: aaghran commentedI was able to get a workaround on this. Submitting a patch. I don't know wether it's the right way or not but it is working now.
Comment #2
Leeteq CreditAttribution: Leeteq commentedHi @aaghran, did you try to attach a patch? (if a problem, just paste the code in code tags)
Comment #3
Jelle_SBy default, Clientside Validation does not validate hidden fields. This is a setting that can be changed. Could you check if that's the problem? If not I'll do some testing myself.