function hide_submit_form_alter in Hide submit button 7
Same name and namespace in other branches
- 5 hide_submit.module \hide_submit_form_alter()
- 6 hide_submit.module \hide_submit_form_alter()
- 7.2 hide_submit.module \hide_submit_form_alter()
Implements hook_form_alter().
Used to add "hide-submit-exclude" class to some forms Avoid conflicts and refine hiding
File
- ./
hide_submit.module, line 135 - Hide the submit button after clicked to prevent/reduce duplicate postings.
Code
function hide_submit_form_alter(&$form, $form_state, $form_id) {
// Act only if script was loaded
if (!hide_submit_js_loaded()) {
return;
}
$exclude_forms = explode("\r\n", variable_get('hide_submit_form_exclusion', ''));
$found = FALSE;
$mode = variable_get('hide_submit_form_exclusion_mode', HIDE_SUBMIT_EXCLUDE_LISTED_FORMS);
// Prevent known conflicts by adding form ids of known ajax forms
if (variable_get('hide_submit_fix_known_conflicts', TRUE) && $mode == HIDE_SUBMIT_EXCLUDE_LISTED_FORMS) {
// shoutbox module
if (module_exists('shoutbox')) {
$exclude_forms[] = 'shoutbox_add_form';
if (_hide_submit_debug_on()) {
drupal_set_message("hide submit: Possible conflict detected and handled - shoutbox module");
}
}
}
foreach ($exclude_forms as $exclude_form_id) {
if ($form_id == $exclude_form_id) {
$found = TRUE;
if ($mode == HIDE_SUBMIT_EXCLUDE_LISTED_FORMS) {
_hide_submit_add_exclude_class($form);
if (_hide_submit_debug_on()) {
drupal_set_message("hide_submit: Excluding form " . $exclude_form_id);
}
}
}
}
if (!$found && $mode == HIDE_SUBMIT_EXCLUDE_UNLISTED_FORMS) {
_hide_submit_add_exclude_class($form);
if (_hide_submit_debug_on()) {
drupal_set_message("hide_submit: Excluding form " . $form_id);
}
}
// Comment workaround
// When disable button mode is selected
// Comments won't submit because disabled button value is not included in the $_POST[] data
// This workaround should fix this
if (($form_id == 'comment_form' || preg_match('/node_form$/', $form_id)) && variable_get('hide_submit_script_mode', HIDE_SUBMIT_MODE_HIDE) == HIDE_SUBMIT_MODE_DISABLE) {
$form['hide_submit_fake_op'] = array(
'#type' => 'hidden',
'#value' => "",
);
}
}