function InputDemo::submitForm
File
-
modules/form_api_example/src/Form/InputDemo.php, line 332
Class
- InputDemo
- Implements InputDemo form controller.
Namespace
Drupal\form_api_example\Form
Code
public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state->getValues();
foreach ($values as $key => $value) {
$label = $form[$key]['#title'] ?? $key;
if (is_array($value)) {
$value = array_filter($value);
}
if ($value && $label) {
$display_value = is_array($value) ? preg_replace('/[\\n\\r\\s]+/', ' ', print_r($value, 1)) : $value;
$message = $this->t('Value for %title: %value', [
'%title' => $label,
'%value' => $display_value,
]);
$this->messenger()
->addMessage($message);
}
}
}