function DbtngExampleAddForm::validateForm
Same name in other branches
- 3.x modules/dbtng_example/src/Form/DbtngExampleAddForm.php \Drupal\dbtng_example\Form\DbtngExampleAddForm::validateForm()
Overrides FormInterface::validateForm
File
-
modules/
dbtng_example/ src/ Form/ DbtngExampleAddForm.php, line 114
Class
- DbtngExampleAddForm
- Form to add a database entry, with all the interesting fields.
Namespace
Drupal\dbtng_example\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
// Verify that the user is logged-in.
if ($this->currentUser
->isAnonymous()) {
$form_state->setError($form['add'], $this->t('You must be logged in to add values to the database.'));
}
// Confirm that age is numeric.
if (!intval($form_state->getValue('age'))) {
$form_state->setErrorByName('age', $this->t('Age needs to be a number'));
}
}