Namespace
Drupal\ajax_example\Form
File
-
modules/ajax_example/src/Form/SubmitDriven.php
View source
<?php
namespace Drupal\ajax_example\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
class SubmitDriven extends FormBase {
public function getFormId() {
return 'ajax_example_autotextfields';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$form['container'] = [
'#type' => 'container',
'#attributes' => [
'id' => 'box-container',
],
];
$form['container']['box'] = [
'#type' => 'markup',
'#markup' => '<h1>Initial markup for box</h1>',
];
$form['submit'] = [
'#type' => 'submit',
'#ajax' => [
'callback' => '::promptCallback',
'wrapper' => 'box-container',
],
'#value' => $this->t('Submit'),
];
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
}
public function promptCallback(array &$form, FormStateInterface $form_state) {
$element = $form['container'];
$element['box']['#markup'] = "Clicked submit ({$form_state->getValue('op')}): " . date('c');
return $element;
}
}
Classes
| Title |
Deprecated |
Summary |
| SubmitDriven |
|
Submit a form without a page reload. |