You are here

function fz152_agreement_element_validate in FZ152 8

Custom validation for FZ152 agreement checkbox.

The common usage of element is contain HTML in label of element. When user submit the form without checking this element, the default form throws error with HTML in it, so, this is fixes the with error when element is not checked.

Parameters

array $element: Form element to be validated.

\Drupal\Core\Form\FormStateInterface $form_state: Current form state.

string $form_id: Submitted form id.

1 string reference to 'fz152_agreement_element_validate'
fz152_form_alter in ./fz152.module
Implements hook_form_alter().

File

./fz152.module, line 131
Main file for hooks and custom functions.

Code

function fz152_agreement_element_validate(array &$element, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  if (!$form_state
    ->getValue('fz152_agreement')) {
    $form_state
      ->setError($element, t('You must agree with privacy policy.'));
  }
}