You are here

function ahah_example_simple_validation_callback in Examples for Developers 6

Callback for simple validation.

Process the form with the number of checkboxes we want to provide.

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

File

ahah_example/ahah_example_simple_validation.inc, line 67
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_callback() {
  $form = ahah_example_callback_helper();

  // This section prepares the actual output that will be returned to the
  // browser.
  $selected_portion = $form['wrapper_fieldset']['two_words_required'];

  // To avoid doubling-up the wrapper, we have to remove it here.
  unset($selected_portion['#prefix'], $selected_portion['#suffix']);

  // Now render and output.
  $output = drupal_render($selected_portion);

  // Include (optionally) the results of any drupal_set_message() calls that
  // may have occurred.
  $output .= theme('status_messages');

  // Output the results and exit.
  drupal_json(array(
    'status' => TRUE,
    'data' => $output,
  ));
  exit;
}