function BuildDemo::buildForm
Same name in other branches
- 3.x modules/form_api_example/src/Form/BuildDemo.php \Drupal\form_api_example\Form\BuildDemo::buildForm()
- 4.0.x modules/form_api_example/src/Form/BuildDemo.php \Drupal\form_api_example\Form\BuildDemo::buildForm()
File
-
form_api_example/
src/ Form/ BuildDemo.php, line 50
Class
- BuildDemo
- Implements the build demo form controller.
Namespace
Drupal\form_api_example\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$form['description'] = [
'#type' => 'item',
'#markup' => $this->t('Demonstrates how submit, rebuild, form-rebuild and #ajax submit work.'),
];
// Simple checkbox for ajax orders.
$form['change'] = [
'#type' => 'checkbox',
'#title' => $this->t('Change Me'),
'#ajax' => [
'callback' => '::ajaxSubmit',
'wrapper' => 'message-wrapper',
],
];
$form['actions'] = [
'#type' => 'actions',
];
// Add a submit button that handles the submission of the form.
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => 'Submit',
];
// Add button handlers.
$form['actions']['button'] = [
'#type' => 'button',
'#value' => 'Rebuild',
];
$form['actions']['rebuild'] = [
'#type' => 'submit',
'#value' => 'Submit Rebuild',
'#submit' => [
'::rebuildFormSubmit',
],
];
$form['actions']['ajaxsubmit'] = [
'#type' => 'submit',
'#value' => 'Ajax Submit',
'#ajax' => [
'callback' => '::ajaxSubmit',
'wrapper' => 'message-wrapper',
],
];
$form['messages'] = [
'#type' => 'container',
'#attributes' => [
'id' => 'message-wrapper',
],
];
return $form;
}