Skip to content

Instantly share code, notes, and snippets.

@mrded
Last active August 29, 2015 14:00
Show Gist options
  • Save mrded/11248206 to your computer and use it in GitHub Desktop.
Save mrded/11248206 to your computer and use it in GitHub Desktop.
Drupal7: Update form element via AJAX.
<?php
function example_form($form, &$form_state) {
$form['foo'] = array(
'#type' => 'select',
'#title' => t('Foo'),
'#options' => array('one', 'two', 'three'),
'#ajax' => array(
'callback' => 'example_foo_callback',
'wrapper' => 'bar-sections'
)
);
if ($form_state['values']['foo']) {
$form['bar'] = array(
'#id' => 'bar-sections',
'#markup' => $form_state['values']['foo'],
);
}
}
function example_foo_callback($form, $form_state) {
return $form['bar'];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment