function SubmitDriven::promptCallback

Same name in other branches
  1. 4.0.x modules/ajax_example/src/Form/SubmitDriven.php \Drupal\ajax_example\Form\SubmitDriven::promptCallback()

Callback for submit_driven example.

Select the 'box' element, change the markup in it, and return it as a renderable array.

Return value

array Renderable array (the box element)

File

modules/ajax_example/src/Form/SubmitDriven.php, line 64

Class

SubmitDriven
Submit a form without a page reload.

Namespace

Drupal\ajax_example\Form

Code

public function promptCallback(array &$form, FormStateInterface $form_state) {
    // In most cases, it is recommended that you put this logic in form
    // generation rather than the callback. Submit driven forms are an
    // exception, because you may not want to return the form at all.
    $element = $form['container'];
    $element['box']['#markup'] = "Clicked submit ({$form_state->getValue('op')}): " . date('c');
    return $element;
}