You are here

function ahah_example_simple_validation in Examples for Developers 6

@file Demonstrate validation of a textfield using AHAH. This approach allows 'live' validation of a field which degrades gracefully when JavaScript is not available.

1 string reference to 'ahah_example_simple_validation'
ahah_example_menu in ahah_example/ahah_example.module
Implement hook_menu().

File

ahah_example/ahah_example_simple_validation.inc, line 9
Demonstrate validation of a textfield using AHAH. This approach allows 'live' validation of a field which degrades gracefully when JavaScript is not available.

Code

function ahah_example_simple_validation(&$form_state) {

  // Wrap the dynamic element in a fieldset, as some themes render the throbber
  // wrong and things appear to jump around on the screen. This can also be
  // fixed with some CSS.
  $form['wrapper_fieldset'] = array(
    '#type' => 'fieldset',
  );
  $form['wrapper_fieldset']['two_words_required'] = array(
    '#title' => t('At least two words are required in this textfield'),
    '#type' => 'textfield',
    '#default_value' => !empty($form_state['values']['two_words_required']) ? $form_state['values']['two_words_required'] : '',
    '#ahah' => array(
      'path' => 'examples/ahah_example/simple_validation/callback',
      'wrapper' => 'two_words_required_wrapper',
    ),
    '#prefix' => '<div id="two_words_required_wrapper">',
    '#suffix' => '</div>',
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Click Me'),
  );
  return $form;
}