1 ajax_example.module ajax_example_submit_driven_ajax($form, &$form_state)

A very basic form which with an AJAX-enabled submit.

On submit, the markup in the #markup element is updated.

Related topics

File

modules/examples/ajax_example/ajax_example.module, line 503
AJAX Examples module file with basic examples.

Code

function ajax_example_submit_driven_ajax($form, &$form_state) {
  $form['box'] = array(
    '#type' => 'markup',
    '#prefix' => '<div id="box">',
    '#suffix' => '</div>',
    '#markup' => '<h1>Initial markup for box</h1>',
  );

  $form['submit'] = array(
    '#type' => 'submit',
    '#ajax' => array(
      'callback' => 'ajax_example_submit_driven_callback',
      'wrapper' => 'box',
    ),
    '#value' => t('Submit'),
  );

  return $form;
}