$form_state->setValue('email', 'example@example.com'); if ($form_state->hasValue('email')) { // Do something if the email field has a value }
if ($form_state->hasValue('checkbox_element') && $form_state->getValue('checkbox_element') == 1) { // Do something if the checkbox element is checked }In this example, the hasValue method is used to check if the 'checkbox_element' has a value and the getValue method is used to check if the checkbox is checked (if its value is equal to 1). Package library: Drupal Core Form module.