Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- return system_settings_from($form);
- <?php
- /**
- * Form manipulation through AJAX.
- */
- function ajax_example_autocheckboxes($form, &$form_state) {
- // Since the form builder is called after every AJAX request, we rebuild
- // the form based on $form_state.
- $num_checkboxes = !empty($form_state['values']['howmany_select']) ? $form_state['values']['howmany_select'] : 1;
- $form['howmany_select'] = array(
- '#title' => t('How many checkboxes do you want?'),
- '#type' => 'select',
- '#options' => array(1 => 1, 2 => 2, 3 => 3, 4 => 4),
- '#default_value' => $num_checkboxes,
- '#ajax' => array(
- 'callback' => 'ajax_example_autocheckboxes_callback',
- 'wrapper' => 'checkboxes-div',
- 'effect' => 'slide',
- ),
- );
- ...
- for ($i = 1; $i <= $num_checkboxes; $i++) {
- $form['checkboxes_fieldset']["checkbox$i"] = array(
- '#type' => 'checkbox',
- '#title' => "Checkbox $i",
- );
- }
- ...
- return $form;
- }
- /**
- * Callback for autocheckboxes.
- *
- * @return array
- * Renderable array (the checkboxes fieldset)
- */
- function ajax_example_autocheckboxes_callback($form, $form_state) {
- return $form['checkboxes_fieldset'];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement