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(&$form, &$form_state) {
$form['account']['checkbox'] = array(
'#type' => 'checkbox',
'#title' => 'Test check',
);
$form['#submit'][] = 'module_simplenews_unsubscribe';
}
//~ //Submit handler for Subscribe/unsubscribe newsletter.
function module_simplenews_unsubscribe($form, &$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?