advanced_form.inc in Lockr 7
Same filename and directory in other branches
Form handlers for advanced admin settings.
File
include/advanced_form.incView source
<?php
/**
* @file
* Form handlers for advanced admin settings.
*/
/**
* Returns form array for advanced settings.
*/
function lockr_admin_advanced_form($advanced_open) {
$form = array(
'#type' => 'fieldset',
'#title' => t('Advanced'),
'#collapsible' => TRUE,
'#collapsed' => !$advanced_open,
);
$form['custom'] = array(
'#type' => 'checkbox',
'#title' => 'Set custom certificate location',
'#default_value' => variable_get('lockr_custom'),
);
$form['custom_cert'] = array(
'#type' => 'textfield',
'#title' => t('Certificate Path'),
'#default_value' => variable_get('lockr_cert'),
'#states' => array(
'visible' => array(
':input[name="custom"]' => array(
'checked' => TRUE,
),
),
),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#validate' => array(
'lockr_admin_advanced_validate',
),
'#submit' => array(
'lockr_admin_advanced_submit',
),
);
return $form;
}
/**
* Validate advanced settings.
*/
function lockr_admin_advanced_validate($form, &$form_state) {
$values = $form_state['values'];
if (!$values['custom']) {
return;
}
$cert_path = $values['custom_cert'];
if (!$cert_path) {
form_set_error('custom_cert', t('Certificate location is required for custom certs'));
return;
}
if ($cert_path[0] != '/') {
$cert_path = DRUPAL_ROOT . "/{$cert_path}";
}
if (is_dir($cert_path) || !is_readable($cert_path)) {
form_set_error('custom_cert', t('Certificate must be a readable file'));
}
}
/**
* Save advanced settings.
*/
function lockr_admin_advanced_submit($form, &$form_state) {
$values = $form_state['values'];
$custom = $values['custom'];
variable_set('lockr_custom', $custom);
if ($custom) {
variable_set('lockr_partner', 'custom');
variable_set('lockr_cert', $values['custom_cert']);
}
else {
$partner = lockr_get_partner();
if ($partner) {
variable_set('lockr_partner', $partner['name']);
variable_set('lockr_cert', $partner['cert']);
}
else {
variable_del('lockr_cert');
}
}
}
Functions
Name | Description |
---|---|
lockr_admin_advanced_form | Returns form array for advanced settings. |
lockr_admin_advanced_submit | Save advanced settings. |
lockr_admin_advanced_validate | Validate advanced settings. |