You are here

public function DbtngExampleAddForm::buildForm in Examples for Developers 3.x

Same name and namespace in other branches
  1. 8 dbtng_example/src/Form/DbtngExampleAddForm.php \Drupal\dbtng_example\Form\DbtngExampleAddForm::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides FormInterface::buildForm

File

modules/dbtng_example/src/Form/DbtngExampleAddForm.php, line 76

Class

DbtngExampleAddForm
Form to add a database entry, with all the interesting fields.

Namespace

Drupal\dbtng_example\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form = [];
  $form['message'] = [
    '#markup' => $this
      ->t('Add an entry to the dbtng_example table.'),
  ];
  $form['add'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Add a person entry'),
  ];
  $form['add']['name'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Name'),
    '#size' => 15,
  ];
  $form['add']['surname'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Surname'),
    '#size' => 15,
  ];
  $form['add']['age'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Age'),
    '#size' => 5,
    '#description' => $this
      ->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'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Add'),
  ];
  return $form;
}