summaryrefslogtreecommitdiff
path: root/modules/simpletest/tests/form_test.module
diff options
context:
space:
mode:
Diffstat (limited to 'modules/simpletest/tests/form_test.module')
-rw-r--r--modules/simpletest/tests/form_test.module83
1 files changed, 83 insertions, 0 deletions
diff --git a/modules/simpletest/tests/form_test.module b/modules/simpletest/tests/form_test.module
index ffc777c42..efd26b773 100644
--- a/modules/simpletest/tests/form_test.module
+++ b/modules/simpletest/tests/form_test.module
@@ -70,6 +70,14 @@ function form_test_menu() {
'type' => MENU_CALLBACK,
);
+ $items['form-test/checkbox'] = array(
+ 'title' => t('Form test'),
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('_form_test_checkbox'),
+ 'access callback' => TRUE,
+ 'type' => MENU_CALLBACK,
+ );
+
return $items;
}
@@ -393,3 +401,78 @@ function form_test_form_state_values_clean_form_submit($form, &$form_state) {
drupal_json_output($form_state['values']);
exit;
}
+
+/**
+ * Build a form to test a checkbox.
+ */
+function _form_test_checkbox($form, &$form_state) {
+ // A required checkbox.
+ $form['required_checkbox'] = array(
+ '#type' => 'checkbox',
+ '#required' => TRUE,
+ '#title' => 'required_checkbox',
+ );
+
+ // A disabled checkbox should get its default value back.
+ $form['disabled_checkbox_on'] = array(
+ '#type' => 'checkbox',
+ '#disabled' => TRUE,
+ '#return_value' => 'disabled_checkbox_on',
+ '#default_value' => 'disabled_checkbox_on',
+ '#title' => 'disabled_checkbox_on',
+ );
+ $form['disabled_checkbox_off'] = array(
+ '#type' => 'checkbox',
+ '#disabled' => TRUE,
+ '#return_value' => 'disabled_checkbox_off',
+ '#default_value' => NULL,
+ '#title' => 'disabled_checkbox_off',
+ );
+
+ // A checkbox is active when #default_value == #return_value.
+ $form['checkbox_on'] = array(
+ '#type' => 'checkbox',
+ '#return_value' => 'checkbox_on',
+ '#default_value' => 'checkbox_on',
+ '#title' => 'checkbox_on',
+ );
+
+ // But inactive in any other case.
+ $form['checkbox_off'] = array(
+ '#type' => 'checkbox',
+ '#return_value' => 'checkbox_off',
+ '#default_value' => 'checkbox_on',
+ '#title' => 'checkbox_off',
+ );
+
+ // Checkboxes with a #return_value of '0' are supported.
+ $form['zero_checkbox_on'] = array(
+ '#type' => 'checkbox',
+ '#return_value' => '0',
+ '#default_value' => '0',
+ '#title' => 'zero_checkbox_on',
+ );
+
+ // In that case, passing a #default_value != '0' means that the checkbox is off.
+ $form['zero_checkbox_off'] = array(
+ '#type' => 'checkbox',
+ '#return_value' => '0',
+ '#default_value' => '1',
+ '#title' => 'zero_checkbox_off',
+ );
+
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+
+ return $form;
+}
+
+/**
+ * Return the form values via JSON.
+ */
+function _form_test_checkbox_submit($form, &$form_state) {
+ drupal_json_output($form_state['values']);
+ exit();
+}