- <?php
- * @file
- * Helper module for the Form API tests.
- */
-
- * Implements hook_menu().
- */
- function form_test_menu() {
- $items['form-test/alter'] = array(
- 'title' => 'Form altering test',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('form_test_alter_form'),
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
- $items['form-test/validate'] = array(
- 'title' => 'Form validation handlers test',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('form_test_validate_form'),
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
- $items['form-test/validate-required'] = array(
- 'title' => 'Form #required validation',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('form_test_validate_required_form'),
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
- $items['form-test/validate-required-no-title'] = array(
- 'title' => 'Form #required validation without #title',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('form_test_validate_required_form_no_title'),
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
- $items['form-test/validate-no-token'] = array(
- 'title' => 'Form validation without a CSRF token',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('form_test_validate_no_token'),
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
- $items['form-test/limit-validation-errors'] = array(
- 'title' => 'Form validation with some error suppression',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('form_test_limit_validation_errors_form'),
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
-
- $items['form_test/tableselect/multiple-true'] = array(
- 'title' => 'Tableselect checkboxes test',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('_form_test_tableselect_multiple_true_form'),
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
- $items['form_test/tableselect/multiple-false'] = array(
- 'title' => 'Tableselect radio button test',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('_form_test_tableselect_multiple_false_form'),
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
- $items['form_test/tableselect/empty-text'] = array(
- 'title' => 'Tableselect empty text test',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('_form_test_tableselect_empty_form'),
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
- $items['form_test/tableselect/advanced-select'] = array(
- 'title' => 'Tableselect js_select tests',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('_form_test_tableselect_js_select_form'),
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
-
- $items['form_test/vertical-tabs'] = array(
- 'title' => 'Vertical tabs tests',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('_form_test_vertical_tabs_form'),
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
-
- $items['form_test/form-storage'] = array(
- 'title' => 'Form storage test',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('form_test_storage_form'),
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
-
- $items['form_test/form-storage-legacy'] = array(
- 'title' => 'Emulate legacy AHAH-style ajax callback',
- 'page callback' => 'form_test_storage_legacy_handler',
- 'delivery callback' => 'backdrop_json_deliver',
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
-
- $items['form_test/form-storage-page-cache'] = array(
- 'title' => 'Form storage with page cache test',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('form_test_storage_page_cache_form'),
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
-
- $items['form_test/wrapper-callback'] = array(
- 'title' => 'Form wrapper callback test',
- 'page callback' => 'form_test_wrapper_callback',
- 'page arguments' => array('form_test_wrapper_callback_form'),
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
-
- $items['form_test/form-state-values-clean'] = array(
- 'title' => 'Form state values clearance test',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('form_test_form_state_values_clean_form'),
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
-
- $items['form_test/form-state-values-clean-advanced'] = array(
- 'title' => 'Form state values clearance advanced test',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('form_test_form_state_values_clean_advanced_form'),
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
-
- $items['form-test/checkbox'] = array(
- 'title' => t('Form test'),
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('_form_test_checkbox'),
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
- $items['form-test/select'] = array(
- 'title' => t('Select'),
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('form_test_select'),
- 'access callback' => TRUE,
- );
- $items['form-test/placeholder-text'] = array(
- 'title' => 'Placeholder',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('form_test_placeholder_test'),
- 'access callback' => TRUE,
- );
- $items['form-test/color'] = array(
- 'title' => 'Color',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('form_test_color'),
- 'access callback' => TRUE,
- );
- $items['form-test/number'] = array(
- 'title' => 'Number',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('form_test_number'),
- 'access callback' => TRUE,
- );
- $items['form-test/number/range'] = array(
- 'title' => 'Range',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('form_test_number', 'range'),
- 'access callback' => TRUE,
- );
- $items['form-test/checkboxes-radios'] = array(
- 'title' => t('Checkboxes, Radios'),
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('form_test_checkboxes_radios'),
- 'access callback' => TRUE,
- );
- $items['form-test/checkboxes-radios-select-indentations'] = array(
- 'title' => t('Checkboxes, Radios and Select indentations'),
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('form_test_checkboxes_radios_select_indentations'),
- 'access callback' => TRUE,
- );
- $items['form-test/email'] = array(
- 'title' => 'Email fields',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('form_test_email'),
- 'access callback' => TRUE,
- );
- $items['form-test/h5datetime'] = array(
- 'title' => 'HTML5 datetime fields',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('form_test_h5datetime'),
- 'access callback' => TRUE,
- );
- $items['form-test/no-access-h5date-h5time'] = array(
- 'title' => 'HTML5 no-access date and time fields',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('form_test_no_access_h5date_h5time'),
- 'access callback' => TRUE,
- );
- $items['form-test/url'] = array(
- 'title' => t('URL'),
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('form_test_url'),
- 'access callback' => TRUE,
- );
-
- $items['form-test/disabled-elements'] = array(
- 'title' => t('Form test'),
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('_form_test_disabled_elements'),
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
-
- $items['form-test/input-forgery'] = array(
- 'title' => t('Form test'),
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('_form_test_input_forgery'),
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
-
- $items['form-test/form-rebuild-preserve-values'] = array(
- 'title' => 'Form values preservation during rebuild test',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('form_test_form_rebuild_preserve_values_form'),
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
-
- $items['form-test/redirect'] = array(
- 'title' => 'Redirect test',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('form_test_redirect'),
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
-
- $items['form_test/form-labels'] = array(
- 'title' => 'Form label test',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('form_label_test_form'),
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
-
- $items['form_test/form-descriptions'] = array(
- 'title' => 'Form description test',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('form_description_test_form'),
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
-
- $items['form-test/state-persist'] = array(
- 'title' => 'Form state persistence without storage',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('form_test_state_persist'),
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
-
- $items['form-test/clicked-button'] = array(
- 'title' => 'Clicked button test',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('form_test_clicked_button'),
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
-
- if (module_exists('node')) {
- $items['form-test/two-instances-of-same-form'] = array(
- 'title' => 'AJAX test with two form instances',
- 'page callback' => 'form_test_two_instances',
- 'access callback' => 'node_access',
- 'access arguments' => array('create', 'page'),
- 'file path' => backdrop_get_path('module', 'node'),
- 'file' => 'node.pages.inc',
- 'type' => MENU_CALLBACK,
- );
- }
- $items['form-test/double-form'] = array(
- 'title' => 'Double form test',
- 'page callback' => 'form_test_double_form',
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
-
- $items['form-test/load-include-menu'] = array(
- 'title' => 'FAPI test loading includes',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('form_test_load_include_menu'),
- 'access callback' => TRUE,
- 'file' => 'form_test.file.inc',
- 'type' => MENU_CALLBACK,
- );
-
- $items['form-test/load-include-custom'] = array(
- 'title' => 'FAPI test loading includes',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('form_test_load_include_custom'),
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
- $items['form-test/checkboxes-zero'] = array(
- 'title' => 'FAPI test involving checkboxes and zero',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('form_test_checkboxes_zero'),
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
- $items['form-test/textarea-resize'] = array(
- 'title' => 'FAPI test for resizable textarea',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('form_test_resizable_textarea'),
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
- $items['form-test/disabled-tabledrag-row'] = array(
- 'title' => 'FAPI test for disabled tabledrag rows',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('form_test_disabled_tabledrag_row'),
- 'access callback' => TRUE,
- 'type' => MENU_CALLBACK,
- );
-
- return $items;
- }
-
- * Form submit handler to return form values as JSON.
- */
- function _form_test_submit_values_json($form, &$form_state) {
- backdrop_json_output($form_state['values']);
- backdrop_exit();
- }
-
- * Form builder for testing hook_form_alter() and hook_form_FORM_ID_alter().
- */
- function form_test_alter_form($form, &$form_state) {
-
-
-
- return $form;
- }
-
- * Implements hook_form_FORM_ID_alter() on behalf of block.module.
- */
- function block_form_form_test_alter_form_alter(&$form, &$form_state) {
- backdrop_set_message('block_form_form_test_alter_form_alter() executed.');
- }
-
- * Implements hook_form_alter().
- */
- function form_test_form_alter(&$form, &$form_state, $form_id) {
- if ($form_id == 'form_test_alter_form') {
- backdrop_set_message('form_test_form_alter() executed.');
- }
- }
-
- * Implements hook_form_FORM_ID_alter().
- */
- function form_test_form_form_test_alter_form_alter(&$form, &$form_state) {
- backdrop_set_message('form_test_form_form_test_alter_form_alter() executed.');
- }
-
- * Implements hook_form_FORM_ID_alter() on behalf of system.module.
- */
- function system_form_form_test_alter_form_alter(&$form, &$form_state) {
- backdrop_set_message('system_form_form_test_alter_form_alter() executed.');
- }
-
- * Form builder for testing backdrop_validate_form().
- *
- * Serves for testing form processing and alterations by form validation
- * handlers, especially for the case of a validation error:
- * - form_set_value() should be able to alter submitted values in
- * $form_state['values'] without affecting the form element.
- * - #element_validate handlers should be able to alter the $element in the form
- * structure and the alterations should be contained in the rebuilt form.
- * - #validate handlers should be able to alter the $form and the alterations
- * should be contained in the rebuilt form.
- */
- function form_test_validate_form($form, &$form_state) {
- $form['name'] = array(
- '#type' => 'textfield',
- '#title' => 'Name',
- '#default_value' => '',
- '#element_validate' => array('form_test_element_validate_name'),
- );
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => 'Save',
- );
-
-
-
- $form_state['cache'] = TRUE;
-
- return $form;
- }
-
- * Form element validation handler for 'name' in form_test_validate_form().
- */
- function form_test_element_validate_name(&$element, &$form_state) {
- $triggered = FALSE;
- if ($form_state['values']['name'] == 'element_validate') {
-
- $element['#value'] = '#value changed by #element_validate';
-
- form_set_value($element, 'value changed by form_set_value() in #element_validate', $form_state);
-
- $triggered = TRUE;
- }
- if ($form_state['values']['name'] == 'element_validate_access') {
- $form_state['storage']['form_test_name'] = $form_state['values']['name'];
-
- $element['#access'] = FALSE;
-
- $triggered = TRUE;
- }
- elseif (!empty($form_state['storage']['form_test_name'])) {
-
- form_set_value($element, $form_state['storage']['form_test_name'], $form_state);
-
- $triggered = TRUE;
- }
-
- if ($triggered) {
-
- backdrop_set_message(t('@label value: @value', array('@label' => $element['#title'], '@value' => $form_state['values']['name'])));
-
-
- form_set_error('');
- }
- }
-
- * Form validation handler for form_test_validate_form().
- */
- function form_test_validate_form_validate(&$form, &$form_state) {
- if ($form_state['values']['name'] == 'validate') {
-
- $form['name']['#value'] = '#value changed by #validate';
-
- form_set_value($form['name'], 'value changed by form_set_value() in #validate', $form_state);
-
- backdrop_set_message(t('@label value: @value', array('@label' => $form['name']['#title'], '@value' => $form_state['values']['name'])));
-
-
- form_set_error('');
- }
- }
-
- * Form constructor to test the #required property.
- */
- function form_test_validate_required_form($form, &$form_state) {
- $options = backdrop_map_assoc(array('foo', 'bar'));
-
- $form['textfield'] = array(
- '#type' => 'textfield',
- '#title' => 'Name',
- '#required' => TRUE,
- '#required_message' => 'Please enter a name.',
-
-
-
-
- '#form_test_expected_message' => 'Please enter a name.',
- );
- $form['checkboxes'] = array(
- '#type' => 'checkboxes',
- '#title' => 'Checkboxes',
- '#options' => $options,
- '#required' => TRUE,
- '#required_message' => 'Please choose at least one option.',
- '#form_test_expected_message' => 'Please choose at least one option.',
- );
- $form['select'] = array(
- '#type' => 'select',
- '#title' => 'Select',
- '#options' => $options,
- '#required' => TRUE,
- '#form_test_expected_message' => 'Select field is required.',
- '#element_validate' => array('form_test_validate_select_element_validate'),
- );
- $form['radios'] = array(
- '#type' => 'radios',
- '#title' => 'Radios',
- '#options' => $options,
- '#required' => TRUE,
- '#form_test_expected_message' => 'Radios field is required.',
- );
- $form['radios_optional'] = array(
- '#type' => 'radios',
- '#title' => 'Radios (optional)',
- '#options' => $options,
- );
- $form['radios_optional_default_value_false'] = array(
- '#type' => 'radios',
- '#title' => 'Radios (optional, with a default value of FALSE)',
- '#options' => $options,
- '#default_value' => FALSE,
- );
- $form['actions'] = array('#type' => 'actions');
- $form['actions']['submit'] = array('#type' => 'submit', '#value' => 'Submit');
- return $form;
- }
-
- * An individual element validator used by form_test_validate_required_form().
- */
- function form_test_validate_select_element_validate($element, &$form_state) {
-
-
- if ($form_state['values']['select'] !== 'foo') {
- form_error($element, 'Please select the "foo" option.');
- }
- }
-
- * Form submission handler for form_test_validate_required_form().
- */
- function form_test_validate_required_form_submit($form, &$form_state) {
- backdrop_set_message('The form_test_validate_required_form form was submitted successfully.');
- }
-
- * Form constructor to test the #required property without #title.
- */
- function form_test_validate_required_form_no_title($form, &$form_state) {
- $form['textfield'] = array(
- '#type' => 'textfield',
- '#required' => TRUE,
- );
- $form['actions'] = array('#type' => 'actions');
- $form['actions']['submit'] = array('#type' => 'submit', '#value' => 'Submit');
- return $form;
- }
-
- * Form submission handler for form_test_validate_required_form_no_title().
- */
- function form_test_validate_required_form_no_title_submit($form, &$form_state) {
- backdrop_set_message('The form_test_validate_required_form_no_title form was submitted successfully.');
- }
-
- * Form builder for testing submission of a form without a CSRF token.
- */
- function form_test_validate_no_token($form, &$form_state) {
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => 'Save',
- );
-
- $form['#token'] = FALSE;
-
- return $form;
- }
-
- * Form submission handler for form_test_validate_no_token().
- */
- function form_test_validate_no_token_submit($form, &$form_state) {
- backdrop_set_message('The form_test_validate_no_token form has been submitted successfully.');
- }
-
- * Builds a simple form with a button triggering partial validation.
- */
- function form_test_limit_validation_errors_form($form, &$form_state) {
- $form['title'] = array(
- '#type' => 'textfield',
- '#title' => 'Title',
- '#required' => TRUE,
- );
-
- $form['test'] = array(
- '#title' => 'Test',
- '#type' => 'textfield',
- '#element_validate' => array('form_test_limit_validation_errors_element_validate_test'),
- );
- $form['test_numeric_index'] = array(
- '#tree' => TRUE,
- );
- $form['test_numeric_index'][0] = array(
- '#title' => 'Test (numeric index)',
- '#type' => 'textfield',
- '#element_validate' => array('form_test_limit_validation_errors_element_validate_test'),
- );
-
- $form['test_substring'] = array(
- '#tree' => TRUE,
- );
- $form['test_substring']['foo'] = array(
- '#title' => 'Test (substring) foo',
- '#type' => 'textfield',
- '#element_validate' => array('form_test_limit_validation_errors_element_validate_test'),
- );
- $form['test_substring']['foobar'] = array(
- '#title' => 'Test (substring) foobar',
- '#type' => 'textfield',
- '#element_validate' => array('form_test_limit_validation_errors_element_validate_test'),
- );
-
- $form['actions']['partial'] = array(
- '#type' => 'submit',
- '#limit_validation_errors' => array(array('test')),
- '#submit' => array('form_test_limit_validation_errors_form_partial_submit'),
- '#value' => t('Partial validate'),
- );
- $form['actions']['partial_numeric_index'] = array(
- '#type' => 'submit',
- '#limit_validation_errors' => array(array('test_numeric_index', 0)),
- '#submit' => array('form_test_limit_validation_errors_form_partial_submit'),
- '#value' => t('Partial validate (numeric index)'),
- );
- $form['actions']['substring'] = array(
- '#type' => 'submit',
- '#limit_validation_errors' => array(array('test_substring', 'foo')),
- '#submit' => array('form_test_limit_validation_errors_form_partial_submit'),
- '#value' => t('Partial validate (substring)'),
- );
- $form['actions']['full'] = array(
- '#type' => 'submit',
- '#value' => t('Full validate'),
- );
- return $form;
- }
-
- * Form element validation handler for the 'test' element.
- */
- function form_test_limit_validation_errors_element_validate_test(&$element, &$form_state) {
- if ($element['#value'] == 'invalid') {
- form_error($element, t('@label element is invalid', array('@label' => $element['#title'])));
- }
- }
-
- * Form submit handler for the partial validation submit button.
- */
- function form_test_limit_validation_errors_form_partial_submit($form, $form_state) {
-
-
- if (!isset($form_state['values']['title']) && isset($form_state['values']['test'])) {
- backdrop_set_message('Only validated values appear in the form values.');
- }
- }
-
- * Create a header and options array. Helper function for callbacks.
- */
- function _form_test_tableselect_get_data() {
- $header = array(
- 'one' => t('One'),
- 'two' => t('Two'),
- 'three' => t('Three'),
- 'four' => t('Four'),
- );
-
- $options['row1'] = array(
- 'one' => 'row1col1',
- 'two' => t('row1col2'),
- 'three' => t('row1col3'),
- 'four' => t('row1col4'),
- );
-
- $options['row2'] = array(
- 'one' => 'row2col1',
- 'two' => t('row2col2'),
- 'three' => t('row2col3'),
- 'four' => t('row2col4'),
- );
-
- $options['row3'] = array(
- 'one' => 'row3col1',
- 'two' => t('row3col2'),
- 'three' => t('row3col3'),
- 'four' => t('row3col4'),
- );
-
- return array($header, $options);
- }
-
- * Build a form to test the tableselect element.
- *
- * @param $form_state
- * The form_state
- * @param $element_properties
- * An array of element properties for the tableselect element.
- *
- * @return
- * A form with a tableselect element and a submit button.
- */
- function _form_test_tableselect_form_builder($form, $form_state, $element_properties) {
- list($header, $options) = _form_test_tableselect_get_data();
-
- $form['tableselect'] = $element_properties;
-
- $form['tableselect'] += array(
- '#prefix' => '<div id="tableselect-wrapper">',
- '#suffix' => '</div>',
- '#type' => 'tableselect',
- '#header' => $header,
- '#options' => $options,
- '#multiple' => FALSE,
- '#empty' => t('Empty text.'),
- '#ajax' => array(
- 'callback' => '_form_test_tableselect_ajax_callback',
- 'wrapper' => 'tableselect-wrapper',
- ),
- );
-
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit'),
- );
-
- return $form;
- }
-
- * Test the tableselect #multiple = TRUE functionality.
- */
- function _form_test_tableselect_multiple_true_form($form, $form_state) {
- return _form_test_tableselect_form_builder($form, $form_state, array('#multiple' => TRUE));
- }
-
- * Process the tableselect #multiple = TRUE submitted values.
- */
- function _form_test_tableselect_multiple_true_form_submit($form, &$form_state) {
- $selected = $form_state['values']['tableselect'];
- foreach ($selected as $key => $value) {
- backdrop_set_message(t('Submitted: @key = @value', array('@key' => $key, '@value' => $value)));
- }
- }
-
- * Test the tableselect #multiple = FALSE functionality.
- */
- function _form_test_tableselect_multiple_false_form($form, $form_state) {
- return _form_test_tableselect_form_builder($form, $form_state, array('#multiple' => FALSE));
- }
-
- * Process the tableselect #multiple = FALSE submitted values.
- */
- function _form_test_tableselect_multiple_false_form_submit($form, &$form_state) {
- backdrop_set_message(t('Submitted: @value', array('@value' => $form_state['values']['tableselect'])));
- }
-
- * Test functionality of the tableselect #empty property.
- */
- function _form_test_tableselect_empty_form($form, $form_state) {
- return _form_test_tableselect_form_builder($form, $form_state, array('#options' => array()));
- }
-
- * Test functionality of the tableselect #js_select property.
- */
- function _form_test_tableselect_js_select_form($form, $form_state, $action) {
- switch ($action) {
- case 'multiple-true-default':
- $options = array('#multiple' => TRUE);
- break;
-
- case 'multiple-false-default':
- $options = array('#multiple' => FALSE);
- break;
-
- case 'multiple-true-no-advanced-select':
- $options = array('#multiple' => TRUE, '#js_select' => FALSE);
- break;
-
- case 'multiple-false-advanced-select':
- $options = array('#multiple' => FALSE, '#js_select' => TRUE);
- break;
- }
-
- return _form_test_tableselect_form_builder($form, $form_state, $options);
- }
-
- * Tests functionality of vertical tabs.
- */
- function _form_test_vertical_tabs_form($form, &$form_state) {
- $form['vertical_tabs'] = array(
- '#type' => 'vertical_tabs',
- );
- $form['tab1'] = array(
- '#type' => 'fieldset',
- '#title' => t('Tab 1'),
- '#collapsible' => TRUE,
- '#group' => 'vertical_tabs',
- );
- $form['tab1']['field1'] = array(
- '#title' => t('Field 1'),
- '#type' => 'textfield',
- );
- $form['tab2'] = array(
- '#type' => 'fieldset',
- '#title' => t('Tab 2'),
- '#collapsible' => TRUE,
- '#group' => 'vertical_tabs',
- );
- $form['tab2']['field2'] = array(
- '#title' => t('Field 2'),
- '#type' => 'textfield',
- );
- return $form;
- }
-
- * Ajax callback that returns the form element.
- */
- function _form_test_tableselect_ajax_callback($form, &$form_state) {
- return $form['tableselect'];
- }
-
- * A multistep form for testing the form storage.
- *
- * It uses two steps for editing a virtual "thing". Any changes to it are saved
- * in the form storage and have to be present during any step. By setting the
- * request parameter "cache" the form can be tested with caching enabled, as
- * it would be the case, if the form would contain some #ajax callbacks.
- *
- * @see form_test_storage_form_submit()
- */
- function form_test_storage_form($form, &$form_state) {
- if ($form_state['rebuild']) {
- $form_state['input'] = array();
- }
-
- if (empty($form_state['storage'])) {
- if (empty($form_state['input'])) {
- $_SESSION['constructions'] = 0;
- }
-
- $form_state['storage'] = array(
- 'thing' => array(
- 'title' => 'none',
- 'value' => '',
- ),
- );
- }
-
- $_SESSION['constructions']++;
- backdrop_set_message("Form constructions: " . $_SESSION['constructions']);
-
- $form['title'] = array(
- '#type' => 'textfield',
- '#title' => 'Title',
- '#default_value' => $form_state['storage']['thing']['title'],
- '#required' => TRUE,
- );
- $form['value'] = array(
- '#type' => 'textfield',
- '#title' => 'Value',
- '#default_value' => $form_state['storage']['thing']['value'],
- '#element_validate' => array('form_test_storage_element_validate_value_cached'),
- );
- $form['continue_button'] = array(
- '#type' => 'button',
- '#value' => 'Reset',
-
- );
- $form['continue_submit'] = array(
- '#type' => 'submit',
- '#value' => 'Continue submit',
- '#submit' => array('form_storage_test_form_continue_submit'),
- );
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => 'Save',
- );
-
- if (isset($_REQUEST['cache'])) {
-
-
- $form_state['cache'] = TRUE;
- }
-
- if (isset($_REQUEST['immutable'])) {
- $form_state['build_info']['immutable'] = TRUE;
- }
-
- return $form;
- }
-
- * Emulate legacy AHAH-style ajax callback.
- *
- * Drupal 6 AHAH callbacks used to operate directly on forms retrieved using
- * form_get_cache and stored using form_set_cache after manipulation. This
- * callback helps testing whether form_set_cache prevents resaving of immutable
- * forms.
- */
- function form_test_storage_legacy_handler($form_build_id) {
- $form_state = array();
- $form = form_get_cache($form_build_id, $form_state);
-
- backdrop_json_output(array(
- 'form' => $form,
- 'form_state' => $form_state,
- ));
-
- $form['#poisoned'] = TRUE;
- $form_state['poisoned'] = TRUE;
-
- form_set_cache($form_build_id, $form, $form_state);
-
-
-
- backdrop_exit();
- }
-
- * Form element validation handler for 'value' element in form_test_storage_form().
- *
- * Tests updating of cached form storage during validation.
- */
- function form_test_storage_element_validate_value_cached($element, &$form_state) {
-
-
-
-
- if (isset($_REQUEST['cache']) && $form_state['values']['value'] == 'change_title') {
- $form_state['storage']['thing']['changed'] = TRUE;
- }
- }
-
- * Form submit handler to continue multi-step form.
- */
- function form_storage_test_form_continue_submit($form, &$form_state) {
- $form_state['storage']['thing']['title'] = $form_state['values']['title'];
- $form_state['storage']['thing']['value'] = $form_state['values']['value'];
- $form_state['rebuild'] = TRUE;
- }
-
- * Form submit handler to finish multi-step form.
- */
- function form_test_storage_form_submit($form, &$form_state) {
- backdrop_set_message("Title: " . check_plain($form_state['values']['title']));
- backdrop_set_message("Form constructions: " . $_SESSION['constructions']);
- if (isset($form_state['storage']['thing']['changed'])) {
- backdrop_set_message("The thing has been changed.");
- }
- $form_state['redirect'] = '<front>';
- }
-
- * A simple form for testing form storage when page caching is enabled.
- */
- function form_test_storage_page_cache_form($form, &$form_state) {
- $form['title'] = array(
- '#type' => 'textfield',
- '#title' => 'Title',
- '#required' => TRUE,
- );
-
- $form['test_build_id_old'] = array(
- '#type' => 'item',
- '#title' => 'Old build id',
- '#markup' => 'No old build id',
- );
-
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => 'Save',
- );
-
- $form['rebuild'] = array(
- '#type' => 'submit',
- '#value' => 'Rebuild',
- '#submit' => array('form_test_storage_page_cache_rebuild'),
- );
-
- $form['#after_build'] = array('form_test_storage_page_cache_old_build_id');
- $form_state['cache'] = TRUE;
-
- return $form;
- }
-
- * Form element #after_build callback: output the old form build-id.
- */
- function form_test_storage_page_cache_old_build_id($form) {
- if (isset($form['#build_id_old'])) {
- $form['test_build_id_old']['#markup'] = check_plain($form['#build_id_old']);
- }
- return $form;
- }
-
- * Form submit callback: Rebuild the form and continue.
- */
- function form_test_storage_page_cache_rebuild($form, &$form_state) {
- $form_state['rebuild'] = TRUE;
- }
-
- * A simple form for testing form caching.
- */
- function form_test_cache_form($form, &$form_state) {
- $form['title'] = array(
- '#type' => 'textfield',
- '#title' => 'Title',
- '#required' => TRUE,
- );
-
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => 'Save',
- );
-
- return $form;
- }
-
- * A form for testing form labels and required marks.
- */
- function form_label_test_form() {
- $form['form_checkboxes_test'] = array(
- '#type' => 'checkboxes',
- '#title' => t('Checkboxes test'),
- '#options' => array(
- 'first-checkbox' => t('First checkbox'),
- 'second-checkbox' => t('Second checkbox'),
- 'third-checkbox' => t('Third checkbox'),
- '0' => t('0'),
- ),
- );
- $form['form_radios_test'] = array(
- '#type' => 'radios',
- '#title' => t('Radios test'),
- '#options' => array(
- 'first-radio' => t('First radio'),
- 'second-radio' => t('Second radio'),
- 'third-radio' => t('Third radio'),
- '0' => t('0'),
- ),
-
- '#field_prefix' => '<span id="form-test-radios-field-prefix">' . t('Radios #field_prefix element') . '</span>',
- '#field_suffix' => '<span id="form-test-radios-field-suffix">' . t('Radios #field_suffix element') . '</span>',
- );
- $form['form_checkbox_test'] = array(
- '#type' => 'checkbox',
- '#title' => t('Checkbox test'),
- );
- $form['form_textfield_test_title_and_required'] = array(
- '#type' => 'textfield',
- '#title' => t('Textfield test for required with title'),
- '#required' => TRUE,
- );
- $form['form_textfield_test_no_title_required'] = array(
- '#type' => 'textfield',
-
-
- '#title' => '',
- '#required' => TRUE,
- );
- $form['form_textfield_test_title'] = array(
- '#type' => 'textfield',
- '#title' => t('Textfield test for title only'),
-
-
- '#prefix' => '<div id="form-test-textfield-title-prefix">' . t('Textfield #prefix element') . '</div>',
- '#suffix' => '<div id="form-test-textfield-title-suffix">' . t('Textfield #suffix element') . '</div>',
- );
- $form['form_textfield_test_title_after'] = array(
- '#type' => 'textfield',
- '#title' => t('Textfield test for title after element'),
- '#title_display' => 'after',
- );
- $form['form_textfield_test_title_invisible'] = array(
- '#type' => 'textfield',
- '#title' => t('Textfield test for invisible title'),
- '#title_display' => 'invisible',
- );
-
- $form['form_textfield_test_title_no_show'] = array(
- '#type' => 'textfield',
- );
-
- $form['form_checkboxes_title_attribute'] = array(
- '#type' => 'checkboxes',
- '#title' => 'Checkboxes test',
- '#options' => array(
- 'first-checkbox' => 'First checkbox',
- 'second-checkbox' => 'Second checkbox',
- ),
- '#title_display' => 'attribute',
- '#required' => TRUE,
- );
- $form['form_radios_title_attribute'] = array(
- '#type' => 'radios',
- '#title' => 'Radios test',
- '#options' => array(
- 'first-radio' => 'First radio',
- 'second-radio' => 'Second radio',
- ),
- '#title_display' => 'attribute',
- '#required' => TRUE,
- );
-
- $form['form_checkboxes_test_title_display_attribute'] = array(
- '#type' => 'checkboxes',
- '#title' => 'Checkboxes, #title_display attribute',
- '#title_display' => 'attribute',
- '#required' => TRUE,
- '#description' => 'Required checkboxes with #title_display attribute and a description.',
- '#options' => backdrop_map_assoc(array('foo', 'bar', 'baz')),
- );
-
- $form['form_checkboxes_test_title_display_attribute'] = array(
- '#type' => 'checkboxes',
- '#title' => 'Checkboxes, #title_display attribute',
- '#title_display' => 'attribute',
- '#required' => TRUE,
- '#description' => 'Required checkboxes with #title_display attribute and a description.',
- '#options' => backdrop_map_assoc(array('foo', 'bar', 'baz')),
- );
-
- return $form;
- }
-
- * A form for testing form descriptions.
- */
- function form_description_test_form() {
- $form['form_textfield_test_description_before'] = array(
- '#type' => 'textfield',
- '#title' => 'Textfield test for description before element',
- '#description' => 'Textfield test for description before element',
- '#description_display' => 'before',
- );
-
- $form['form_textfield_test_description_after'] = array(
- '#type' => 'textfield',
- '#title' => 'Textfield test for description after element',
- '#description' => 'Textfield test for description after element',
- '#description_display' => 'after',
- );
-
- $form['form_textfield_test_description_invisible'] = array(
- '#type' => 'textfield',
- '#title' => 'Textfield test for visually-hidden description',
- '#description' => 'Textfield test for visually-hidden description',
- '#description_display' => 'invisible',
- );
-
- $form['form_checkboxes_test_description_before'] = array(
- '#type' => 'checkboxes',
- '#title' => t('Checkboxes test for description before element'),
- '#description' => 'Checkboxes test for description before element',
- '#options' => array(
- 'first-checkbox' => t('First checkbox'),
- 'second-checkbox' => t('Second checkbox'),
- ),
- );
-
- $form['form_radios_test_description_before'] = array(
- '#type' => 'radios',
- '#title' => 'Radios test for description before element',
- '#description' => 'Radios test for description before element',
- '#options' => array(
- 'first-radio' => 'First radio',
- 'second-radio' => 'Second radio',
- ),
- );
-
- $form['form_textarea_test_description_before'] = array(
- '#type' => 'textarea',
- '#title' => t('Textarea test for description before element'),
- '#description' => 'Radios test for description before element',
- );
-
- $form['form_checkboxes_test_description_after'] = array(
- '#type' => 'checkboxes',
- '#title' => t('Checkboxes test for description after element'),
- '#description' => 'Checkboxes test for description after element',
- '#description_display' => 'after',
- '#options' => array(
- 'first-checkbox' => t('First checkbox'),
- 'second-checkbox' => t('Second checkbox'),
- ),
- );
-
- $form['form_radios_test_description_after'] = array(
- '#type' => 'radios',
- '#title' => t('Radios test for description after element'),
- '#description' => 'Radios test for description after element',
- '#description_display' => 'after',
- '#options' => array(
- 'first-radio' => 'First radio',
- 'second-radio' => 'Second radio',
- ),
- );
-
- $form['form_textarea_test_description_after'] = array(
- '#type' => 'textarea',
- '#title' => t('Textarea test for description after element'),
- '#description' => 'Radios test for description after element',
- '#description_display' => 'after',
- );
-
- return $form;
- }
-
- * Menu callback; Invokes a form builder function with a wrapper callback.
- */
- function form_test_wrapper_callback($form_id) {
- $form_state = array(
- 'build_info' => array('args' => array()),
- 'wrapper_callback' => 'form_test_wrapper_callback_wrapper',
- );
- return backdrop_build_form($form_id, $form_state);
- }
-
- * Form wrapper for form_test_wrapper_callback_form().
- */
- function form_test_wrapper_callback_wrapper($form, &$form_state) {
- $form['wrapper'] = array('#markup' => 'Form wrapper callback element output.');
- return $form;
- }
-
- * Form builder for form wrapper callback test.
- */
- function form_test_wrapper_callback_form($form, &$form_state) {
- $form['builder'] = array('#markup' => 'Form builder element output.');
- return $form;
- }
-
- * Form builder for form_state_values_clean() test.
- */
- function form_test_form_state_values_clean_form($form, &$form_state) {
-
-
- $form = array('#tree' => TRUE);
- $form['foo'] = array('#type' => 'submit', '#value' => t('Submit'));
- $form['bar'] = array('#type' => 'submit', '#value' => t('Submit'));
- $form['beer'] = array('#type' => 'value', '#value' => 1000);
- $form['baz']['foo'] = array('#type' => 'button', '#value' => t('Submit'));
- $form['baz']['baz'] = array('#type' => 'submit', '#value' => t('Submit'));
- $form['baz']['beer'] = array('#type' => 'value', '#value' => 2000);
- return $form;
- }
-
- * Form submit handler for form_state_values_clean() test form.
- */
- function form_test_form_state_values_clean_form_submit($form, &$form_state) {
- form_state_values_clean($form_state);
- backdrop_json_output($form_state['values']);
- exit;
- }
-
- * Form constructor for the form_state_values_clean() test.
- */
- function form_test_form_state_values_clean_advanced_form($form, &$form_state) {
-
- $form['image'] = array(
- '#type' => 'managed_file',
- '#title' => t('Image'),
- '#upload_location' => 'public://',
- '#default_value' => 0,
- );
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit'),
- );
- return $form;
- }
-
- * Form submission handler for form_test_form_state_values_clean_advanced_form().
- */
- function form_test_form_state_values_clean_advanced_form_submit($form, &$form_state) {
- form_state_values_clean($form_state);
- print t('You WIN!');
- exit;
- }
-
- * Build a form to test a checkbox.
- */
- function _form_test_checkbox($form, &$form_state) {
-
- $form['required_checkbox'] = array(
- '#type' => 'checkbox',
- '#required' => TRUE,
- '#title' => 'required_checkbox',
- );
-
-
- $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',
- );
-
-
- $form['checkbox_on'] = array(
- '#type' => 'checkbox',
- '#return_value' => 'checkbox_on',
- '#default_value' => 'checkbox_on',
- '#title' => 'checkbox_on',
- );
-
-
- $form['checkbox_off'] = array(
- '#type' => 'checkbox',
- '#return_value' => 'checkbox_off',
- '#default_value' => 'checkbox_on',
- '#title' => 'checkbox_off',
- );
-
-
- $form['zero_checkbox_on'] = array(
- '#type' => 'checkbox',
- '#return_value' => '0',
- '#default_value' => '0',
- '#title' => 'zero_checkbox_on',
- );
-
-
- $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) {
- backdrop_json_output($form_state['values']);
- exit();
- }
-
- * Builds a form to test #type 'select' validation.
- */
- function form_test_select($form, &$form_state) {
- $base = array(
- '#type' => 'select',
- '#options' => backdrop_map_assoc(array('one', 'two', 'three')),
- );
-
- $form['select'] = $base + array(
- '#title' => '#default_value one',
- '#default_value' => 'one',
- );
- $form['select_required'] = $base + array(
- '#title' => '#default_value one, #required',
- '#required' => TRUE,
- '#default_value' => 'one',
- );
- $form['select_optional'] = $base + array(
- '#title' => '#default_value one, not #required',
- '#required' => FALSE,
- '#default_value' => 'one',
- );
- $form['empty_value'] = $base + array(
- '#title' => '#default_value one, #required, #empty_value 0',
- '#required' => TRUE,
- '#default_value' => 'one',
- '#empty_value' => 0,
- );
- $form['empty_value_one'] = $base + array(
- '#title' => '#default_value = #empty_value, #required',
- '#required' => TRUE,
- '#default_value' => 'one',
- '#empty_value' => 'one',
- );
-
- $form['no_default'] = $base + array(
- '#title' => 'No #default_value, #required',
- '#required' => TRUE,
- );
- $form['no_default_optional'] = $base + array(
- '#title' => 'No #default_value, not #required',
- '#required' => FALSE,
- '#description' => 'Should result in "one" because it is not required and there is no #empty_value requested, so default browser behavior of preselecting first option is in effect.',
- );
- $form['no_default_optional_empty_value'] = $base + array(
- '#title' => 'No #default_value, not #required, #empty_value empty string',
- '#empty_value' => '',
- '#required' => FALSE,
- '#description' => 'Should result in an empty string (due to #empty_value) because it is optional.',
- );
-
- $form['no_default_empty_option'] = $base + array(
- '#title' => 'No #default_value, #required, #empty_option',
- '#required' => TRUE,
- '#empty_option' => '- Choose -',
- );
- $form['no_default_empty_option_optional'] = $base + array(
- '#title' => 'No #default_value, not #required, #empty_option',
- '#empty_option' => '- Dismiss -',
- '#description' => 'Should result in an empty string (default of #empty_value) because it is optional.',
- );
-
- $form['no_default_empty_value'] = $base + array(
- '#title' => 'No #default_value, #required, #empty_value 0',
- '#required' => TRUE,
- '#empty_value' => 0,
- '#description' => 'Should never result in 0.',
- );
- $form['no_default_empty_value_one'] = $base + array(
- '#title' => 'No #default_value, #required, #empty_value one',
- '#required' => TRUE,
- '#empty_value' => 'one',
- '#description' => 'A mistakenly assigned #empty_value contained in #options should not be valid.',
- );
- $form['no_default_empty_value_optional'] = $base + array(
- '#title' => 'No #default_value, not #required, #empty_value 0',
- '#required' => FALSE,
- '#empty_value' => 0,
- '#description' => 'Should result in 0 because it is optional.',
- );
-
- $form['multiple'] = $base + array(
- '#title' => '#multiple, #default_value two',
- '#default_value' => array('two'),
- '#multiple' => TRUE,
- );
- $form['multiple_no_default'] = $base + array(
- '#title' => '#multiple, no #default_value',
- '#multiple' => TRUE,
- );
- $form['multiple_no_default_required'] = $base + array(
- '#title' => '#multiple, #required, no #default_value',
- '#required' => TRUE,
- '#multiple' => TRUE,
- );
-
- $form['submit'] = array('#type' => 'submit', '#value' => 'Submit');
- return $form;
- }
-
- * Form submit handler for form_test_select().
- */
- function form_test_select_submit($form, &$form_state) {
- backdrop_json_output($form_state['values']);
- exit();
- }
-
- * Form constructor for testing #type 'color' elements.
- *
- * @see form_test_color_submit()
- * @ingroup forms
- */
- function form_test_color($form, &$form_state) {
- $form['color'] = array(
- '#type' => 'color',
- '#title' => 'Color',
- );
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => 'Submit',
- );
- return $form;
- }
-
- * Builds a form to test #type 'number' and 'range' validation.
- *
- * @param $element
- * The element type to test. Can be 'number' or 'range'. Defaults to 'number'.
- */
- function form_test_number($form, &$form_state, $element = 'number') {
- $base = array(
- '#type' => $element,
- );
-
- $form['integer_no_number'] = $base + array(
- '#title' => 'Integer test, #no_error',
- '#default_value' => '#no_number',
- );
- $form['integer_no_step'] = $base + array(
- '#title' => 'Integer test without step',
- '#default_value' => 5,
- );
- $form['integer_no_step_step_error'] = $base + array(
- '#title' => 'Integer test without step, #step_error',
- '#default_value' => 4.5,
- );
- $form['integer_step'] = $base + array(
- '#title' => 'Integer test with step',
- '#default_value' => 5,
- '#step' => 1,
- );
- $form['integer_step_error'] = $base + array(
- '#title' => 'Integer test, with step, #step_error',
- '#default_value' => 5,
- '#step' => 2,
- );
- $form['integer_step_min'] = $base + array(
- '#title' => 'Integer test with min value',
- '#default_value' => 5,
- '#min' => 0,
- '#step' => 1,
- );
- $form['integer_step_min_error'] = $base + array(
- '#title' => 'Integer test with min value, #min_error',
- '#default_value' => 5,
- '#min' => 6,
- '#step' => 1,
- );
- $form['integer_step_max'] = $base + array(
- '#title' => 'Integer test with max value',
- '#default_value' => 5,
- '#max' => 6,
- '#step' => 1,
- );
- $form['integer_step_max_error'] = $base + array(
- '#title' => 'Integer test with max value, #max_error',
- '#default_value' => 5,
- '#max' => 4,
- '#step' => 1,
- );
- $form['integer_step_min_border'] = $base + array(
- '#title' => 'Integer test with min border check',
- '#default_value' => -1,
- '#min' => -1,
- '#step' => 1,
- );
- $form['integer_step_max_border'] = $base + array(
- '#title' => 'Integer test with max border check',
- '#default_value' => 5,
- '#max' => 5,
- '#step' => 1,
- );
- $form['integer_step_based_on_min'] = $base + array(
- '#title' => 'Integer test with step based on min check',
- '#default_value' => 3,
- '#min' => -1,
- '#step' => 2,
- );
- $form['integer_step_based_on_min_error'] = $base + array(
- '#title' => 'Integer test with step based on min check, #step_error',
- '#default_value' => 4,
- '#min' => -1,
- '#step' => 2,
- );
- $form['float_small_step'] = $base + array(
- '#title' => 'Float test with a small step',
- '#default_value' => 4,
- '#step' => 0.0000000000001,
- );
- $form['float_step_no_error'] = $base + array(
- '#title' => 'Float test',
- '#default_value' => 1.2,
- '#step' => 0.3,
- );
- $form['float_step_error'] = $base + array(
- '#title' => 'Float test, #step_error',
- '#default_value' => 1.3,
- '#step' => 0.3,
- );
- $form['float_step_hard_no_error'] = $base + array(
- '#title' => 'Float test hard',
- '#default_value' => 0.9411764729088,
- '#step' => 0.0392156863712,
- );
- $form['float_step_hard_error'] = $base + array(
- '#title' => 'Float test hard, #step_error',
- '#default_value' => 0.9411764,
- '#step' => 0.00392156863,
- );
- $form['float_step_any_no_error'] = $base + array(
- '#title' => 'Arbitrary float',
- '#default_value' => 0.839562930284,
- '#step' => 'aNy',
- );
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => 'Submit',
- );
-
- return $form;
- }
-
- * Form submission handler for form_test_color().
- */
- function form_test_color_submit($form, &$form_state) {
- backdrop_json_output($form_state['values']);
- exit;
- }
-
- * Builds a form to test the placeholder attribute.
- */
- function form_test_placeholder_test($form, &$form_state) {
- foreach (array('textfield', 'textarea', 'url', 'search', 'password', 'tel', 'number') as $type) {
- $form[$type] = array(
- '#type' => $type,
- '#title' => $type,
- '#placeholder' => 'placeholder-text',
- );
- }
-
- return $form;
- }
-
- * Form constructor to test expansion of #type checkboxes and radios.
- */
- function form_test_checkboxes_radios($form, &$form_state, $customize = FALSE) {
- $form['#submit'] = array('_form_test_submit_values_json');
-
-
-
- $form['checkboxes'] = array(
- '#type' => 'checkboxes',
- '#title' => 'Checkboxes',
- '#options' => array(
- 0 => 'Zero',
- 'foo' => 'Foo',
- 1 => 'One',
- 'bar' => 'Bar',
- '>' => 'Special Char',
- ),
- );
- if ($customize) {
- $form['checkboxes'] += array(
- 'foo' => array(
- '#description' => 'Enable to foo.',
- ),
- 1 => array(
- '#weight' => 10,
- ),
- );
- }
-
-
-
- $form['radios'] = array(
- '#type' => 'radios',
- '#title' => 'Radios',
- '#options' => array(
- 0 => 'Zero',
- 'foo' => 'Foo',
- 1 => 'One',
- 'bar' => 'Bar',
- '>' => 'Special Char',
- ),
- );
- if ($customize) {
- $form['radios'] += array(
- 'foo' => array(
- '#description' => 'Enable to foo.',
- ),
- 1 => array(
- '#weight' => 10,
- ),
- );
- }
-
- $form['submit'] = array('#type' => 'submit', '#value' => 'Submit');
-
- return $form;
- }
-
- * Form constructor to test indentations for radios, checkboxes and select.
- */
- function form_test_checkboxes_radios_select_indentations($form, &$form_state) {
- $form['checkboxes'] = array(
- '#type' => 'checkboxes',
- '#title' => 'Indented checkboxes',
- '#options' => array(
- 0 => 'No indentation',
- 'foo' => 'One indentation',
- 3 => 'No indentation 2',
- 'bar' => 'Two indentations',
- ),
- );
- $form['checkboxes']['foo']['#indentation'] = 1;
- $form['checkboxes']['bar']['#indentation'] = 2;
-
- $form['radios'] = array(
- '#type' => 'radios',
- '#title' => 'Indented radios',
- '#options' => array(
- 0 => 'No indentation',
- 'foo' => 'One indentation',
- 3 => 'No indentation 2',
- 'bar' => 'Two indentations',
- ),
- );
- $form['radios']['foo']['#indentation'] = 1;
- $form['radios']['bar']['#indentation'] = 2;
-
- $form['select'] = array(
- '#type' => 'select',
- '#title' => 'Indented select',
- '#options' => array(
- 0 => 'No indentation',
- 'foo' => 'One indentation',
- 3 => 'No indentation 2',
- 'bar' => 'Two indentations',
- ),
- );
- $form['select']['foo']['#indentation'] = 1;
- $form['select']['bar']['#indentation'] = 2;
-
- return $form;
- }
-
- * Form constructor for testing #type 'email' elements.
- *
- * @see form_test_email_submit()
- * @ingroup forms
- */
- function form_test_email($form, &$form_state) {
- $form['email'] = array(
- '#type' => 'email',
- '#title' => 'Email address',
- '#description' => 'An email address.',
- );
- $form['email_required'] = array(
- '#type' => 'email',
- '#title' => 'Address',
- '#required' => TRUE,
- '#description' => 'A required email address field.',
- );
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => 'Submit',
- );
- return $form;
- }
-
- * Form submission handler for form_test_email().
- */
- function form_test_email_submit($form, &$form_state) {
- backdrop_json_output($form_state['values']);
- exit();
- }
-
- * Form constructor for #type html_date, html_time and html_datetime elements.
- *
- * @see form_test_h5datetime_submit()
- * @ingroup forms
- */
- function form_test_h5datetime($form, &$form_state) {
- $form['h5date'] = array(
- '#type' => 'html_date',
- '#title' => 'Date',
- '#description' => 'A date.',
- );
- $form['h5time'] = array(
- '#type' => 'html_time',
- '#title' => 'Time',
- '#description' => 'A time.',
- );
- $form['h5datetime'] = array(
- '#type' => 'html_datetime',
- '#title' => 'Datetime',
- '#description' => 'A date and time combo.',
- );
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => 'Submit',
- );
- return $form;
- }
-
- * Form submission handler for form_test_h5datetime().
- */
- function form_test_h5datetime_submit($form, &$form_state) {
- backdrop_json_output($form_state['values']);
- exit();
- }
-
- * Form constructor for disabled html_date and html_time elements.
- *
- * @see form_test_no_access_h5date_h5time_submit()
- */
- function form_test_no_access_h5date_h5time($form, &$form_state) {
- $form['no_access_h5date'] = array(
- '#type' => 'html_date',
- '#title' => 'Date',
- '#description' => 'A date.',
- '#default_value' => array(
- 'date' => '2023-01-01',
- ),
- '#access' => FALSE,
- );
- $form['no_access_h5time'] = array(
- '#type' => 'html_time',
- '#title' => 'Time',
- '#description' => 'A time.',
- '#default_value' => array(
- 'time' => '20:30',
- ),
- '#access' => FALSE,
- );
- $form['disabled_h5date'] = array(
- '#type' => 'html_date',
- '#title' => 'Date',
- '#description' => 'A date.',
- '#default_value' => array(
- 'date' => '2023-01-01',
- ),
- '#disabled' => TRUE,
- );
- $form['disabled_h5time'] = array(
- '#type' => 'html_time',
- '#title' => 'Time',
- '#description' => 'A time.',
- '#default_value' => array(
- 'time' => '20:30',
- ),
- '#disabled' => TRUE,
- );
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => 'Submit',
- );
- return $form;
- }
-
- * Form submission handler for form_test_disabled_h5datetime().
- */
- function form_test_no_access_h5date_h5time_submit($form, &$form_state) {
- backdrop_json_output($form_state['values']);
- exit();
- }
-
- * Form constructor for testing #type 'url' elements.
- *
- * @see form_test_url_submit()
- * @ingroup forms
- */
- function form_test_url($form, &$form_state) {
- $form['url'] = array(
- '#type' => 'url',
- '#title' => 'Optional URL',
- '#description' => 'An optional URL field.',
- );
- $form['url_required'] = array(
- '#type' => 'url',
- '#title' => 'Required URL',
- '#description' => 'A required URL field.',
- '#required' => TRUE,
- );
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => 'Submit',
- );
- return $form;
- }
-
- * Form submission handler for form_test_url().
- */
- function form_test_url_submit($form, &$form_state) {
- backdrop_json_output($form_state['values']);
- exit();
- }
-
- * Build a form to test disabled elements.
- */
- function _form_test_disabled_elements($form, &$form_state) {
-
- foreach (array('textfield', 'textarea', 'search', 'tel', 'hidden') as $type) {
- $form[$type] = array(
- '#type' => $type,
- '#title' => $type,
- '#default_value' => $type,
- '#test_hijack_value' => 'HIJACK',
- '#disabled' => TRUE,
- );
- }
-
-
- foreach (array('checkboxes', 'select') as $type) {
- $form[$type . '_multiple'] = array(
- '#type' => $type,
- '#title' => $type . ' (multiple)',
- '#options' => array(
- 'test_1' => 'Test 1',
- 'test_2' => 'Test 2',
- ),
- '#multiple' => TRUE,
- '#default_value' => array('test_2' => 'test_2'),
-
-
- '#test_hijack_value' => $type == 'select' ? array('' => 'test_1') : array('test_1' => 'test_1'),
- '#disabled' => TRUE,
- );
- }
-
-
- foreach (array('radios', 'select') as $type) {
- $form[$type . '_single'] = array(
- '#type' => $type,
- '#title' => $type . ' (single)',
- '#options' => array(
- 'test_1' => 'Test 1',
- 'test_2' => 'Test 2',
- ),
- '#multiple' => FALSE,
- '#default_value' => 'test_2',
- '#test_hijack_value' => 'test_1',
- '#disabled' => TRUE,
- );
- }
-
-
- foreach (array('checkbox', 'radio') as $type) {
- $form[$type . '_unchecked'] = array(
- '#type' => $type,
- '#title' => $type . ' (unchecked)',
- '#return_value' => 1,
- '#default_value' => 0,
- '#test_hijack_value' => 1,
- '#disabled' => TRUE,
- );
- $form[$type . '_checked'] = array(
- '#type' => $type,
- '#title' => $type . ' (checked)',
- '#return_value' => 1,
- '#default_value' => 1,
- '#test_hijack_value' => NULL,
- '#disabled' => TRUE,
- );
- }
-
-
- $form['weight'] = array(
- '#type' => 'weight',
- '#title' => 'weight',
- '#default_value' => 10,
- '#test_hijack_value' => 5,
- '#disabled' => TRUE,
- );
-
-
- $form['color'] = array(
- '#type' => 'color',
- '#title' => 'color',
- '#disabled' => TRUE,
- '#default_value' => '#0000ff',
- '#test_hijack_value' => '#ff0000',
- '#disabled' => TRUE,
- );
-
-
- $form['number'] = array(
- '#type' => 'number',
- '#title' => 'number',
- '#disabled' => TRUE,
- '#default_value' => 1,
- '#test_hijack_value' => 2,
- );
-
-
- foreach (array('weight', 'number', 'range') as $type) {
- $form[$type] = array(
- '#type' => $type,
- '#title' => $type,
- '#default_value' => 10,
- '#test_hijack_value' => 5,
- '#disabled' => TRUE,
- );
- }
-
-
- $form['date'] = array(
- '#type' => 'date',
- '#title' => 'date',
- '#disabled' => TRUE,
- '#default_value' => array(
- 'day' => '16',
- 'month' => '01',
- 'year' => '2015',
- ),
- '#test_hijack_value' => array(
- 'day' => '16',
- 'month' => '09',
- 'year' => '2016',
- ),
- );
-
-
- $form['disabled_container'] = array(
- '#disabled' => TRUE,
- );
- foreach (array('textfield', 'textarea', 'hidden', 'tel', 'url') as $type) {
- $form['disabled_container']['disabled_container_' . $type] = array(
- '#type' => $type,
- '#title' => $type,
- '#default_value' => $type,
- '#test_hijack_value' => 'HIJACK',
- );
- }
-
-
- $form['disabled_container']['disabled_container_url'] = array(
- '#type' => 'url',
- '#title' => 'url',
- '#default_value' => 'http://example.com',
- '#test_hijack_value' => 'http://example.com/foo',
- );
-
-
- $form['text_format'] = array(
- '#type' => 'text_format',
- '#title' => 'Text format',
- '#disabled' => TRUE,
- '#default_value' => 'Text value',
- '#format' => 'plain_text',
- '#expected_value' => array(
- 'value' => 'Text value',
- 'format' => 'plain_text',
- ),
- '#test_hijack_value' => array(
- 'value' => 'HIJACK',
- 'format' => 'filtered_html',
- ),
- );
-
-
- $form['password'] = array(
- '#type' => 'password',
- '#title' => 'Password',
- '#disabled' => TRUE,
- );
- $form['password_confirm'] = array(
- '#type' => 'password_confirm',
- '#title' => 'Password confirm',
- '#disabled' => TRUE,
- );
-
-
- $form['file'] = array(
- '#type' => 'file',
- '#title' => 'File',
- '#disabled' => TRUE,
- );
- $form['managed_file'] = array(
- '#type' => 'managed_file',
- '#title' => 'Managed file',
- '#disabled' => TRUE,
- );
-
-
- $form['image_button'] = array(
- '#type' => 'image_button',
- '#value' => 'Image button',
- '#disabled' => TRUE,
- );
- $form['button'] = array(
- '#type' => 'button',
- '#value' => 'Button',
- '#disabled' => TRUE,
- );
- $form['submit_disabled'] = array(
- '#type' => 'submit',
- '#value' => 'Submit',
- '#disabled' => TRUE,
- );
-
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit'),
- );
-
- return $form;
- }
-
- * Return the form values via JSON.
- */
- function _form_test_disabled_elements_submit($form, &$form_state) {
- backdrop_json_output($form_state['values']);
- exit();
- }
-
- * Build a form to test input forgery of enabled elements.
- */
- function _form_test_input_forgery($form, &$form_state) {
-
-
- $form['checkboxes'] = array(
- '#type' => 'checkboxes',
- '#options' => array(
- 'one' => 'One',
- 'two' => 'Two',
- ),
- );
-
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit'),
- );
- return $form;
- }
-
- * Return the form values via JSON.
- */
- function _form_test_input_forgery_submit($form, &$form_state) {
- backdrop_json_output($form_state['values']);
- exit();
- }
-
- * Form builder for testing preservation of values during a rebuild.
- */
- function form_test_form_rebuild_preserve_values_form($form, &$form_state) {
-
-
- $form = array(
- 'checkbox_1_default_off' => array(
- '#type' => 'checkbox',
- '#title' => t('This checkbox defaults to unchecked.'),
- '#default_value' => FALSE,
- ),
- 'checkbox_1_default_on' => array(
- '#type' => 'checkbox',
- '#title' => t('This checkbox defaults to checked.'),
- '#default_value' => TRUE,
- ),
- 'text_1' => array(
- '#type' => 'textfield',
- '#title' => t('This textfield has a non-empty default value.'),
- '#default_value' => 'DEFAULT 1',
- ),
- );
-
-
-
-
- if (empty($form_state['storage']['add_more'])) {
- $form['add_more'] = array(
- '#type' => 'submit',
- '#value' => 'Add more',
- '#submit' => array('form_test_form_rebuild_preserve_values_form_add_more'),
- );
- }
- else {
- $form += array(
- 'checkbox_2_default_off' => array(
- '#type' => 'checkbox',
- '#title' => t('This checkbox defaults to unchecked.'),
- '#default_value' => FALSE,
- ),
- 'checkbox_2_default_on' => array(
- '#type' => 'checkbox',
- '#title' => t('This checkbox defaults to checked.'),
- '#default_value' => TRUE,
- ),
- 'text_2' => array(
- '#type' => 'textfield',
- '#title' => t('This textfield has a non-empty default value.'),
- '#default_value' => 'DEFAULT 2',
- ),
- );
- }
-
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => 'Submit',
- );
- return $form;
- }
-
- * Button submit handler for form_test_form_rebuild_preserve_values_form().
- */
- function form_test_form_rebuild_preserve_values_form_add_more($form, &$form_state) {
-
- $form_state['storage']['add_more'] = TRUE;
- $form_state['rebuild'] = TRUE;
- }
-
- * Form submit handler for form_test_form_rebuild_preserve_values_form().
- */
- function form_test_form_rebuild_preserve_values_form_submit($form, &$form_state) {
-
- backdrop_set_message(t('Form values: %values', array('%values' => var_export($form_state['values'], TRUE))));
- }
-
- * Form constructor for testing form state persistence.
- */
- function form_test_state_persist($form, &$form_state) {
- $form['title'] = array(
- '#type' => 'textfield',
- '#title' => 'title',
- '#default_value' => 'DEFAULT',
- '#required' => TRUE,
- );
- $form_state['value'] = 'State persisted.';
-
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit'),
- );
- return $form;
- }
-
- * Submit handler.
- *
- * @see form_test_state_persist()
- */
- function form_test_state_persist_submit($form, &$form_state) {
- backdrop_set_message($form_state['value']);
- $form_state['rebuild'] = TRUE;
- }
-
- * Implements hook_form_FORM_ID_alter().
- *
- * @see form_test_state_persist()
- */
- function form_test_form_form_test_state_persist_alter(&$form, &$form_state) {
-
-
- if (!empty($_REQUEST['cache'])) {
- $form_state['cache'] = TRUE;
- }
- }
-
- * Form builder to test programmatic form submissions.
- */
- function form_test_programmatic_form($form, &$form_state) {
- $form['textfield'] = array(
- '#title' => 'Textfield',
- '#type' => 'textfield',
- );
-
- $form['checkboxes'] = array(
- '#type' => 'checkboxes',
- '#options' => array(
- 1 => 'First checkbox',
- 2 => 'Second checkbox',
- ),
-
-
- '#default_value' => array(1, 2),
- );
-
-
-
- $form['textfield_no_access'] = array(
- '#type' => 'textfield',
- '#title' => 'Textfield no access',
- '#default_value' => 'default value',
- '#access' => FALSE,
- );
-
- $form['field_to_validate'] = array(
- '#type' => 'radios',
- '#title' => 'Field to validate (in the case of limited validation)',
- '#description' => 'If the form is submitted by clicking the "Submit with limited validation" button, then validation can be limited based on the value of this radio button.',
- '#options' => array(
- 'all' => 'Validate all fields',
- 'textfield' => 'Validate the "Textfield" field',
- 'field_to_validate' => 'Validate the "Field to validate" field',
- ),
- '#default_value' => 'all',
- );
-
-
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => 'Submit',
- );
-
-
- $form['submit_limit_validation'] = array(
- '#type' => 'submit',
- '#value' => 'Submit with limited validation',
-
-
-
- '#submit' => array('form_test_programmatic_form_submit'),
- );
- if (!empty($form_state['input']['field_to_validate']) && $form_state['input']['field_to_validate'] != 'all') {
- $form['submit_limit_validation']['#limit_validation_errors'] = array(
- array($form_state['input']['field_to_validate']),
- );
- }
-
- return $form;
- }
-
- * Form validation handler for programmatic form submissions.
- *
- * To test that the validation handler is correctly executed, the field value is
- * explicitly required here.
- */
- function form_test_programmatic_form_validate($form, &$form_state) {
- if (empty($form_state['values']['textfield'])) {
- form_set_error('textfield', t('Textfield is required.'));
- }
- }
-
- * Form submit handler for programmatic form submissions.
- *
- * To test that the submission handler is correctly executed, we store the
- * submitted values in a place we can access from the caller context.
- */
- function form_test_programmatic_form_submit($form, &$form_state) {
- $form_state['storage']['programmatic_form_submit'] = $form_state['values'];
- }
-
- * Form builder to test button click detection.
- */
- function form_test_clicked_button($form, &$form_state) {
-
-
-
-
-
- $form['text'] = array(
- '#title' => 'Text',
- '#type' => 'textfield',
- );
-
-
-
-
-
-
- $i=0;
- $args = array_slice(arg(), 2);
- foreach ($args as $arg) {
- $name = 'button' . ++$i;
-
- if (strpos($arg, 's') !== FALSE) {
- $type = 'submit';
- }
- elseif (strpos($arg, 'b') !== FALSE) {
- $type = 'button';
- }
- elseif (strpos($arg, 'i') !== FALSE) {
- $type = 'image_button';
- }
- else {
- $type = NULL;
- }
- if (isset($type)) {
- $form[$name] = array(
- '#type' => $type,
- '#name' => $name,
- );
-
- if ($type == 'image_button') {
- $form[$name]['#src'] = 'core/misc/feed.png';
- }
- else {
- $form[$name]['#value'] = $name;
- }
-
-
- if (strpos($arg, 'r') !== FALSE) {
- $form[$name]['#access'] = FALSE;
- }
- }
- }
-
- return $form;
- }
-
- * Form validation handler for the form_test_clicked_button() form.
- */
- function form_test_clicked_button_validate($form, &$form_state) {
- if (isset($form_state['triggering_element'])) {
- backdrop_set_message(t('The clicked button is %name.', array('%name' => $form_state['triggering_element']['#name'])));
- }
- else {
- backdrop_set_message('There is no clicked button.');
- }
- }
-
- * Form submit handler for the form_test_clicked_button() form.
- */
- function form_test_clicked_button_submit($form, &$form_state) {
- backdrop_set_message('Submit handler for form_test_clicked_button executed.');
- }
-
- * Form builder to detect form redirect.
- */
- function form_test_redirect($form, &$form_state) {
- $form['redirection'] = array(
- '#type' => 'checkbox',
- '#title' => t('Use redirection'),
- );
- $form['destination'] = array(
- '#type' => 'textfield',
- '#title' => t('Redirect destination'),
- '#states' => array(
- 'visible' => array(
- ':input[name="redirection"]' => array('checked' => TRUE),
- ),
- ),
- );
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit'),
- );
-
- return $form;
- }
-
- * Form submit handler to test different redirect behaviours.
- */
- function form_test_redirect_submit(&$form, &$form_state) {
- if (!empty($form_state['values']['redirection'])) {
- $form_state['redirect'] = !empty($form_state['values']['destination']) ? $form_state['values']['destination'] : NULL;
- }
- else {
- $form_state['redirect'] = FALSE;
- }
- }
-
- * Implements hook_form_FORM_ID_alter() for the registration form.
- */
- function form_test_form_user_register_form_alter(&$form, &$form_state) {
- $form['test_rebuild'] = array(
- '#type' => 'submit',
- '#value' => t('Rebuild'),
- '#submit' => array('form_test_user_register_form_rebuild'),
- );
-
- if (!empty($_REQUEST['field'])) {
- $node = entity_create('node', array(
- 'type' => 'page',
- ));
- field_attach_form('node', $node, $form, $form_state);
- }
- }
-
- * Submit callback that just lets the form rebuild.
- */
- function form_test_user_register_form_rebuild($form, &$form_state) {
- backdrop_set_message('Form rebuilt.');
- $form_state['rebuild'] = TRUE;
- }
-
- * Menu callback that returns two instances of the node form.
- */
- function form_test_two_instances() {
- global $user;
- $node1 = entity_create('node', array(
- 'uid' => $user->uid,
- 'name' => (isset($user->name) ? $user->name : ''),
- 'type' => 'page',
- 'langcode' => LANGUAGE_NONE,
- ));
- $node2 = clone($node1);
- $return['node_form_1'] = backdrop_get_form('page_node_form', $node1);
- $return['node_form_2'] = backdrop_get_form('page_node_form', $node2);
- return $return;
- }
-
- * Menu callback for testing custom form includes.
- */
- function form_test_load_include_custom($form, &$form_state) {
- $form['button'] = array(
- '#type' => 'submit',
- '#value' => t('Save'),
- '#submit' => array('form_test_load_include_submit'),
- );
-
-
-
-
- form_load_include($form_state, 'inc', 'form_test', 'form_test.file');
- $form_state['cache'] = TRUE;
- return $form;
- }
-
- function form_test_checkbox_type_juggling($form, $form_state, $default_value, $return_value) {
- $form['checkbox'] = array(
- '#type' => 'checkbox',
- '#return_value' => $return_value,
- '#default_value' => $default_value,
- );
- return $form;
- }
-
- function form_test_checkboxes_zero($form, &$form_state, $json = TRUE) {
- $form['checkbox_off'] = array(
- '#type' => 'checkboxes',
- '#options' => array('foo', 'bar', 'baz'),
- );
- $form['checkbox_zero_default'] = array(
- '#type' => 'checkboxes',
- '#options' => array('foo', 'bar', 'baz'),
- '#default_value' => array(0),
- );
- $form['checkbox_string_zero_default'] = array(
- '#type' => 'checkboxes',
- '#options' => array('foo', 'bar', 'baz'),
- '#default_value' => array('0'),
- );
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => 'Save',
- );
- if ($json) {
- $form['#submit'][] = '_form_test_submit_values_json';
- }
- else {
- $form['#submit'][] = '_form_test_checkboxes_zero_no_redirect';
- }
- return $form;
- }
-
- function _form_test_checkboxes_zero_no_redirect($form, &$form_state) {
- $form_state['redirect'] = FALSE;
- }
-
- * Menu callback for form-test/textarea-resize.
- */
- function form_test_resizable_textarea($form, &$form_state) {
- $form['text-true'] = array(
- '#type' => 'textarea',
- '#title' => 'Test',
- '#resizable' => TRUE,
- );
- $form['text-false'] = array(
- '#type' => 'textarea',
- '#title' => 'Test',
- '#resizable' => FALSE,
- );
- $form['text-vertical'] = array(
- '#type' => 'textarea',
- '#title' => 'Test',
- '#resizable' => 'vertical',
- );
- $form['text-horizontal'] = array(
- '#type' => 'textarea',
- '#title' => 'Test',
- '#resizable' => 'horizontal',
- );
- $form['text-none'] = array(
- '#type' => 'textarea',
- '#title' => 'Test',
- '#resizable' => 'none',
- );
- $form['text-wrong'] = array(
- '#type' => 'textarea',
- '#title' => 'Test',
- '#resizable' => 'true',
- );
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => 'Save',
- );
- return $form;
- }
-
- * Menu callback returns two instances of the same form.
- */
- function form_test_double_form() {
- return array(
- 'form1' => backdrop_get_form('form_test_html_id'),
- 'form2' => backdrop_get_form('form_test_html_id'),
- );
- }
-
- * Builds a simple form to test duplicate HTML IDs.
- */
- function form_test_html_id($form, &$form_state) {
- $form['name'] = array(
- '#type' => 'textfield',
- '#title' => 'name',
- '#required' => TRUE,
- );
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => 'Save',
- );
- return $form;
- }
-
- * A form to test system_settings_form().
- */
- function form_test_system_config_form() {
- $config = config('simpletest.testconfig');
- $form['#config'] = 'simpletest.testconfig';
- $form['abc'] = array(
- '#type' => 'textfield',
- '#title' => 'abc',
- '#default_value' => $config->get('abc'),
- );
- $form['def'] = array(
- '#type' => 'textfield',
- '#title' => 'def',
- '#default_value' => $config->get('def'),
- );
-
-
- $system_config = config('system.core');
- $form['rss_description'] = array(
- '#type' => 'textfield',
- '#title' => 'xyz',
- '#default_value' => $system_config->get('rss_description'),
- '#config' => 'system.core',
- );
-
-
- $second_config = config('simpletest.secondconfig');
- $form['second_settings'] = array(
- '#type' => 'fieldset',
- '#title' => 'Second Settings',
- '#config' => 'simpletest.secondconfig',
- );
- $form['second_settings']['ghi'] = array(
- '#type' => 'textfield',
- '#title' => 'ghi',
- '#default_value' => $second_config->get('ghi')
- );
- $form['second_settings']['jkl'] = array(
- '#type' => 'textfield',
- '#title' => 'jkl',
- '#default_value' => $second_config->get('jkl')
- );
-
- return system_settings_form($form);
- }
-
- * Menu callback for testing disabled tabledrag rows.
- */
- function form_test_disabled_tabledrag_row($form, &$form_state) {
- $options = array(
- 1 => array(
- 'title' => 'How to Learn Backdrop',
- 'content_type' => 'Post',
- 'status' => 'published',
- ),
- 3 => array(
- 'title' => 'Privacy Policy',
- 'content_type' => 'Page',
- 'status' => 'published',
- ),
- 5 => array(
- 'title' => 'Disabled row',
- 'content_type' => 'Page',
- 'status' => 'published',
- '#disabled' => TRUE,
- ),
- );
- $header = array(
- 'title' => t('Title'),
- 'content_type' => t('Content type'),
- 'status' => t('Status'),
- );
- $form['tabledrag_test'] = array(
- '#type' => 'tableselect',
- '#options' => $options,
- '#header' => $header,
- );
- $form['actions'] = array(
- '#type' => 'actions',
- 'submit' => array(
- '#type' => 'submit',
- '#value' => 'Submit',
- ),
- );
- return $form;
- }