1 dbtng_example.module dbtng_example_form_add($form, &$form_state)

Prepare a simple form to add an entry, with all the interesting fields.

Related topics

File

modules/examples/dbtng_example/dbtng_example.module, line 387
This is an example outlining how a module can make use of the DBTNG database API in Backdrop.

Code

function dbtng_example_form_add($form, &$form_state) {
  $form = array();

  $form['add'] = array(
    '#type' => 'fieldset',
    '#title' => t('Add a person entry'),
  );
  $form['add']['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#size' => 15,
  );
  $form['add']['surname'] = array(
    '#type' => 'textfield',
    '#title' => t('Surname'),
    '#size' => 15,
  );
  $form['add']['age'] = array(
    '#type' => 'textfield',
    '#title' => t('Age'),
    '#size' => 5,
    '#description' => t("Values greater than 127 will cause an exception. Try it - it's a great example why exception handling is needed with DTBNG."),
  );
  $form['add']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Add'),
  );

  return $form;
}