Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. return system_settings_from($form);
  2.  
  3. <?php
  4. /**
  5. * Form manipulation through AJAX.
  6. */
  7. function ajax_example_autocheckboxes($form, &$form_state) {
  8.  
  9. // Since the form builder is called after every AJAX request, we rebuild
  10. // the form based on $form_state.
  11. $num_checkboxes = !empty($form_state['values']['howmany_select']) ? $form_state['values']['howmany_select'] : 1;
  12.  
  13. $form['howmany_select'] = array(
  14. '#title' => t('How many checkboxes do you want?'),
  15. '#type' => 'select',
  16. '#options' => array(1 => 1, 2 => 2, 3 => 3, 4 => 4),
  17. '#default_value' => $num_checkboxes,
  18. '#ajax' => array(
  19. 'callback' => 'ajax_example_autocheckboxes_callback',
  20. 'wrapper' => 'checkboxes-div',
  21. 'effect' => 'slide',
  22. ),
  23. );
  24.  
  25. ...
  26.  
  27. for ($i = 1; $i <= $num_checkboxes; $i++) {
  28. $form['checkboxes_fieldset']["checkbox$i"] = array(
  29. '#type' => 'checkbox',
  30. '#title' => "Checkbox $i",
  31. );
  32. }
  33.  
  34. ...
  35.  
  36. return $form;
  37. }
  38.  
  39.  
  40. /**
  41. * Callback for autocheckboxes.
  42. *
  43. * @return array
  44. * Renderable array (the checkboxes fieldset)
  45. */
  46. function ajax_example_autocheckboxes_callback($form, $form_state) {
  47. return $form['checkboxes_fieldset'];
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement