1 form_example_elements.inc form_example_element_demo_form($form, &$form_state)

Form content for examples/form_example/element_example.

Simple form to demonstrate how to use the various new FAPI elements we've defined.

File

modules/examples/form_example/form_example_elements.inc, line 468
This is an example demonstrating how a module can define custom form and render elements.

Code

function form_example_element_demo_form($form, &$form_state) {
  $config = config('form_example.settings');

  $form['a_form_example_textfield'] = array(
    '#type' => 'form_example_textfield',
    '#title' => t('Form Example textfield'),
    '#default_value' => $config->get('form_example_textfield'),
    '#description' => t('form_example_textfield is a new type, but it is actually uses the system-provided functions of textfield'),
  );

  $form['a_form_example_checkbox'] = array(
    '#type' => 'form_example_checkbox',
    '#title' => t('Form Example checkbox'),
    '#default_value' => $config->get('form_example_checkbox'),
    '#description' => t('Nothing more than a regular checkbox but with a theme provided by this module.'),
  );

  $form['a_form_example_element_discrete'] = array(
    '#type' => 'form_example_phonenumber_discrete',
    '#title' => t('Discrete phone number'),
    '#default_value' => $config->get('form_example_element_discrete'),
    '#description' => t('A phone number : areacode (XXX), prefix (XXX) and extension (XXXX). This one uses a "discrete" element type, one which stores the three parts of the telephone number separately.'),
  );

  $form['a_form_example_element_combined'] = array(
    '#type' => 'form_example_phonenumber_combined',
    '#title' => t('Combined phone number'),
    '#default_value' => $config->get('form_example_element_combined'),
    '#description' => t('form_example_element_combined one uses a "combined" element type, one with a single 10-digit value which is broken apart when needed.'),
  );

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  );

  return $form;
}