public function WebformSubmissionForm::validateForm in Webform 6.x
Same name and namespace in other branches
- 8.5 src/WebformSubmissionForm.php \Drupal\webform\WebformSubmissionForm::validateForm()
Button-level validation handlers are highly discouraged for entity forms, as they will prevent entity validation from running. If the entity is going to be saved during the form submission, this method should be manually invoked from the button-level validation handler, otherwise an exception will be thrown.
Overrides ContentEntityForm::validateForm
1 call to WebformSubmissionForm::validateForm()
- WebformTemplatesSubmissionPreviewForm::validateForm in modules/
webform_templates/ src/ WebformTemplatesSubmissionPreviewForm.php - Button-level validation handlers are highly discouraged for entity forms, as they will prevent entity validation from running. If the entity is going to be saved during the form submission, this method should be manually invoked from the button-level…
1 method overrides WebformSubmissionForm::validateForm()
- WebformTemplatesSubmissionPreviewForm::validateForm in modules/
webform_templates/ src/ WebformTemplatesSubmissionPreviewForm.php - Button-level validation handlers are highly discouraged for entity forms, as they will prevent entity validation from running. If the entity is going to be saved during the form submission, this method should be manually invoked from the button-level…
File
- src/
WebformSubmissionForm.php, line 1766
Class
- WebformSubmissionForm
- Provides a webform to collect and edit submissions.
Namespace
Drupal\webformCode
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
// Disable inline form error when performing validation via the API.
if ($this->operation === 'api') {
// @see \Drupal\webform\WebformSubmissionForm::submitWebformSubmission
$form['#disable_inline_form_errors'] = TRUE;
}
// Build webform submission with validated and processed data.
$this->entity = $this
->buildEntity($form, $form_state);
// Server side #states API validation.
$this->conditionsValidator
->validateForm($form, $form_state);
// Validate webform via webform handler.
$this
->getWebform()
->invokeHandlers('validateForm', $form, $form_state, $this->entity);
// Webform validate handlers (via form['#validate']) are not called when
// #validate handlers are attached to the trigger element
// (i.e. submit button), so we need to manually call $form['validate']
// handlers to support the modules that use form['#validate'] like the
// validators.module.
// @see \Drupal\webform\WebformSubmissionForm::actions
// @see \Drupal\Core\Form\FormBuilder::doBuildForm
$trigger_element = $form_state
->getTriggeringElement();
if (isset($trigger_element['#validate'])) {
$handlers = array_filter($form['#validate'], function ($callback) {
// Remove ::validateForm to prevent a recursion.
return is_array($callback) || $callback !== '::validateForm';
});
// @see \Drupal\Core\Form\FormValidator::executeValidateHandlers
foreach ($handlers as $callback) {
$arguments = [
&$form,
&$form_state,
];
call_user_func_array($form_state
->prepareCallback($callback), $arguments);
}
}
// Validate file (upload) limit.
$this
->validateUploadedManagedFiles($form, $form_state);
}