Drupal - How can I force users to provide a reason when cancelling their accounts?
Here you go, alter the user_cancel_confirm_form.
function MYMODULE_form_user_cancel_confirm_form_alter(&$form, &$form_state, $form_id) {
$form['reason'] = array(
'#title' => t('Reason'),
'#type' => 'textarea',
'#description' => t('We are sad to see you go, why do you want to leave?'),
'#required' => TRUE, // force to input
);
$form['#submit'][] = 'user_cancel_log_reason'; // add custom submit handler
}
function user_cancel_log_reason($form, &$form_state) {
$reason = $form_state['values']['reason'];
// do whatever with the reason, e.g watchdog
watchdog('user', 'User cancel reason:' . $reason);
}