I have created the country and state fields with the Webform module, and I want to add a field validation for the state field when user select US as country.
How can I achieve this?
I have created the country and state fields with the Webform module, and I want to add a field validation for the state field when user select US as country.
How can I achieve this?
The Webform Validation module should add the features you need.
This module adds an extra tab to each webform node, allowing you to specify validation rules for your webform components. You can create one or more of the predefined validation rules, and select which webform component(s) should be validated against those. By using the hooks provided by this module, you can also define your own validation rules in your own modules.
If you need something more in depth or with possibly more control then check out the answer linked to in the question comments.
Make use of the validate function in hook_form_alter:
if ($form_id == 'webform_client_form_14') {
$form['#validate'][] = 'cork_creation_validate_custom';
}
function cork_creation_validate_custom($form, &$form_state) {
if (!preg_match('/^[A-Za-z]+$/', $form_state['values']['submitted']['name'])) {
// $form['submitted'][$key]['#attributes']['class'] = 'error';
form_set_error('name', t('Please enter alphabets only for Name.'));
}
}