function hide_submit_admin_settings in Hide submit button 5
Same name and namespace in other branches
- 6 hide_submit_admin.inc \hide_submit_admin_settings()
- 7 hide_submit_admin.inc \hide_submit_admin_settings()
Implementation of admin_settings callback
1 string reference to 'hide_submit_admin_settings'
- hide_submit_menu in ./
hide_submit.module - Implementation of hook_menu
File
- ./
hide_submit_admin.inc, line 90 - Hide the submit button after clicked to prevent/reduce duplicate postings.
Code
function hide_submit_admin_settings() {
drupal_add_js(drupal_get_path('module', 'hide_submit') . '/hide_submit_admin_settings.js');
$default_img = drupal_get_path('module', 'hide_submit') . '/images/' . HIDE_SUBMIT_DEFAULT_IMAGE_BASENAME;
$image_dir = file_directory_path() . HIDE_SUBMIT_IMG_DIRECTORY;
// Check for a new uploaded image, and use that instead.
if ($file = file_save_upload('hide_submit_image_upload')) {
if (file_check_directory($image_dir, FILE_CREATE_DIRECTORY, 'hide_submit_image_upload')) {
if (file_copy($file, $image_dir, FILE_EXISTS_RENAME)) {
$_POST['hide_submit_custom_image_link'] = $file->filepath;
$_POST['hide_submit_toggle_custom_image'] = 0;
}
}
}
// Create the form
$form = array();
// --- PREVIEW ---
$form['fieldset_preview'] = array(
'#type' => 'fieldset',
'#title' => t('Preview of current animation and message settings'),
'#collapsible' => FALSE,
);
$form['fieldset_preview']['preview'] = array(
'#type' => 'markup',
'#id' => 'hide-submit-preview-user',
'#value' => filter_xss_admin(_hide_submit_clean_for_javascript(_hide_submit_get_message())),
);
// --- LOAD OPTIONS FIELDSET ---
$form['fieldset_js_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Script settings'),
'#collapsible' => TRUE,
);
$form['fieldset_js_settings']['hide_submit_script_mode'] = array(
'#type' => 'radios',
'#title' => t('Script mode'),
'#default_value' => variable_get('hide_submit_script_mode', HIDE_SUBMIT_MODE_HIDE),
'#options' => array(
HIDE_SUBMIT_MODE_HIDE => t('Hide buttons and display message'),
HIDE_SUBMIT_MODE_DISABLE => t('Disable buttons'),
),
'#description' => t("What the script shall do? hide the buttons or disable them"),
);
$form['fieldset_js_settings']['hide_submit_js_load_option'] = array(
'#type' => 'radios',
'#title' => t('Javascript load options'),
'#default_value' => variable_get('hide_submit_js_load_option', HIDE_SUBMIT_DEFAULT_JS_LOAD),
'#options' => array(
HIDE_SUBMIT_IN_CONTENT_ADD_EDIT => t('Add/Edit node pages only'),
HIDE_SUBMIT_IN_ALL_PAGES => t('Every page'),
HIDE_SUBMIT_IN_LISTED_PAGES => t('Only on the listed pages.'),
HIDE_SUBMIT_EXCLUDE_LISTED_PAGES => t('Every page except the listed pages.'),
),
'#description' => t("Add/Edit node view will load for pages with url '/node/add' and '/node/*/edit'. Every page, is well, EVERY PAGE. For the last two options use the page list box to set a list of include/exclude urls."),
);
$form['fieldset_js_settings']['hide_submit_js_load_pages'] = array(
'#type' => 'textarea',
'#title' => t('Page list'),
'#default_value' => variable_get('hide_submit_js_load_pages', ''),
'#description' => t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array(
'%blog' => 'blog',
'%blog-wildcard' => 'blog/*',
'%front' => '<front>',
)),
);
// --- MESSAGE ---
$form['fieldset_message'] = array(
'#type' => 'fieldset',
'#title' => t('Message'),
'#collapsible' => TRUE,
'#description' => t("The message to print after submit is clicked and the button become invisible. i.e. Please wait.."),
);
$form['fieldset_message']['hide_submit_message'] = array(
'#type' => 'textarea',
'#title' => t('Default Message'),
'#rows' => 2,
'#default_value' => variable_get('hide_submit_message', t('Please wait...')),
);
// --- IMAGE SELECTION FIELDSET ---
$form['fieldset_images'] = array(
'#type' => 'fieldset',
'#title' => t('Image or animation'),
'#collapsible' => FALSE,
'#theme' => 'hide_submit_images_fieldset',
);
// jpg, jpeg, gif, png
$mask = "^.+\\.(([jJ][pP][gG)|([jJ][pP][eE][gG])|([gG][iI][fF])|([pP][nN][gG]))\$";
$default_images = file_scan_directory(drupal_get_path('module', 'hide_submit') . '/images', $mask);
$user_images = file_scan_directory($image_dir, $mask);
$options = array();
foreach (array_merge($default_images, $user_images) as $image_file) {
//$count = 1;
$key = md5($image_file->basename);
$options[$key] = '';
$list_of_images[$key] = $image_file->filename;
$form['fieldset_images']['hide_submit_images'][$key]['image'] = array(
'#type' => 'markup',
'#title' => $image_file->basename,
'#value' => theme('image', $image_file->filename),
);
}
$form['list_of_images'] = array(
'#type' => 'value',
'#value' => $list_of_images,
);
foreach ($user_images as $image_file) {
$key = md5($image_file->basename);
$form['fieldset_images']['hide_submit_images'][$key]['operations'] = array(
'#value' => l(t('delete'), 'admin/settings/hide-submit/delete/' . $image_file->basename),
);
}
$form['fieldset_images']['hide_submit_random'] = array(
'#type' => 'checkboxes',
'#default_value' => variable_get('hide_submit_random', array()),
'#options' => $options,
);
$form['fieldset_images']['hide_submit_default_image'] = array(
'#type' => 'radios',
'#default_value' => variable_get('hide_submit_default_image', md5(HIDE_SUBMIT_DEFAULT_IMAGE_BASENAME)),
'#options' => $options,
);
$form['fieldset_images']["hide_submit_toggle_custom_image"] = array(
'#type' => 'checkbox',
'#title' => t('Use custom link'),
'#default_value' => variable_get('hide_submit_toggle_custom_image', 0),
'#tree' => FALSE,
'#description' => t('Check here if you want use a custom image link.'),
);
$form['fieldset_images']['hide_submit_custom_image_link'] = array(
'#prefix' => '<div id="edit-hide-submit-custom-image-link-wrapper">',
'#suffix' => '</div>',
'#type' => 'textfield',
'#title' => t('Custom image or animation'),
'#default_value' => variable_get('hide_submit_custom_image_link', $default_img),
'#description' => t("A link to an image, this image will be added to message.."),
);
// Upload picture
$form['#attributes']['enctype'] = 'multipart/form-data';
$form['fieldset_images']['hide_submit_image_upload'] = array(
'#type' => 'file',
'#title' => t('Upload picture'),
'#size' => 48,
'#description' => t('Upload image or gif animation to display with the message.'),
);
$form['fieldset_images']["hide_submit_toggle_random"] = array(
'#type' => 'checkbox',
'#title' => t('Randomize images'),
'#default_value' => variable_get('hide_submit_toggle_random', 0),
'#tree' => FALSE,
'#description' => t('Check here if you want use random image each time the script loads. You need to check the <em>random</em> box for at least two images'),
);
// --- Advanced ---
$form['fieldset_advanced'] = array(
'#type' => 'fieldset',
'#title' => t('Advanced'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['fieldset_advanced']['hide_submit_form_exclusion_mode'] = array(
'#type' => 'radios',
'#title' => t('Exclusion mode'),
'#default_value' => variable_get('hide_submit_form_exclusion_mode', HIDE_SUBMIT_EXCLUDE_LISTED_FORMS),
'#options' => array(
HIDE_SUBMIT_EXCLUDE_LISTED_FORMS => t('Exclude listed forms'),
HIDE_SUBMIT_EXCLUDE_UNLISTED_FORMS => t('Exclude unlisted forms'),
),
'#description' => t("Choose exclusion mode for listed forms. <br /> NOTE: Forms that are not part of drupal Form-API will not be affected by this configuration"),
);
$form['fieldset_advanced']['hide_submit_form_exclusion'] = array(
'#type' => 'textarea',
'#title' => t('Form-id exclusion list'),
'#default_value' => variable_get('hide_submit_form_exclusion', 'shoutbox_add_form'),
'#description' => t("Here you can make a list of forms (form-id) you wish not to hide submit buttons . <br />For example you can exclude the login block submit button from hiding by typing <em>user_login_block</em>"),
);
$form['fieldset_advanced']['hide_submit_attribute_filter'] = array(
'#type' => 'textarea',
'#title' => t('Attribute Filter (Experimental)'),
'#default_value' => variable_get('hide_submit_attribute_filter', ''),
'#description' => t("Here you can make a list of attribute filters see %selectors for formatting details<br />For example to filter the 'Save as draft' button type [value!=Save As Draft]", array(
'%selectors' => l(t('Attribute Filters:'), 'http://docs.jquery.com/Selectors'),
)),
);
$form['fieldset_advanced']["hide_submit_debug"] = array(
'#type' => 'checkbox',
'#title' => t('Enable debugging'),
'#default_value' => variable_get('hide_submit_debug', FALSE),
'#tree' => FALSE,
'#description' => t('Debugging turned on will paint included and excluded submit buttons'),
);
$form['#validate'] = array(
'hide_submit_admin_settings_validate' => array(),
);
// add extra submit handler (also run the default handler)
$form['#submit'] = array(
'system_settings_form_submit' => array(),
'_hide_submit_admin_settings_submit' => array(),
);
return system_settings_form($form);
}