Print message only if checkbox field is alter using form alter I have created a checkbox in user edit using form alter and based checkbox state I want to print the message. For this I used below code

function module_form_user_profile_form_alter(&amp;$form, &amp;$form_state) {

  $form['account']['checkbox'] = array(
    '#type' =&gt; 'checkbox',
    '#title' =&gt; 'Test check',
   );
   $form['#submit'][] = 'module_simplenews_unsubscribe';
}

//~ //Submit handler for Subscribe/unsubscribe newsletter.
function module_simplenews_unsubscribe($form, &amp;$form_state) {

  if ($form['account']['checkbox']['#value'] == 0) {
    drupal_set_message(t("You are checked"));
  }
 if ($form['account']['checkbox']['#value'] == 1) {

    drupal_set_message(t("You are unchecked"));
  }
}


It works fine. When checkbox is checked/unchecked and user saves the profile it prints respective message. But when user doesn't modify this checkbox field and modify some other field and saves, again it prints message based on checkbox state.

I want to display the message only when checkbox field is modified. How can I achieve this?
You can use form_state instead of form in your submit handler and use default_value of check box in your form alter

$form['account']['checkbox'] = array(
    '#type' =&gt; 'checkbox',
    '#title' =&gt; 'Test check',
    '#default_value' =&gt; 0,
   );


and then your submit handler will go like this

function module_simplenews_unsubscribe($form, &amp;$form_state) {

  if ($form_state['values']['checkbox'] == 0) {
    drupal_set_message(t("You are checked"));
  }
 if ($form_state['values']['checkbox'] == 1) {

    drupal_set_message(t("You are unchecked"));
  }


Use debug tools for proper index of form_state for checkbox.