Last active
August 29, 2015 14:00
-
-
Save mrded/11248206 to your computer and use it in GitHub Desktop.
Drupal7: Update form element via AJAX.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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