How can I programmatically get a checkbox value? I need to check if &quot;Close this ticket after replying&quot; checkbox is checked or not. The value $ab is not getting displayed. This is a comment type created from Structure &gt; Comment Type.
function helper_ticket_comment_submit(&amp;$form, FormStateInterface $form_state)
{
          $ab = $form_state -&gt;getValue('field_close_this_ticket'); 
           \Drupal::logger('CheckBoxValue')-&gt;notice($ab);
           
 }


Error:
Install the Devel module and then use its dpm() function to print a variable to the message area of your page. So inside your submit handler put dpm($form_state-&gt;getValue('field_close_this_ticket')); and you'll see what the error message already is telling you: It's an array. While the logger expects a string. What you are looking for is inside $form_state-&gt;getValue('field_close_this_ticket')['value'], note the ['value'] at the end.
function helper_ticket_comment_submit(&amp;$form, \Drupal\Core\Form\FormStateInterface $form_state) {

  if ($form_state-&gt;hasValue('field_close_this_ticket') &amp;&amp; $form_state-&gt;getValue('field_close_this_ticket')['value'] == TRUE) {

    \Drupal::service('messenger')-&gt;addMessage(t('Ticket closed'));
  }
}