function restrict_by_ip_form_alter in Restrict Login or Role Access by IP Address 6.3
Same name and namespace in other branches
- 8.4 restrict_by_ip.module \restrict_by_ip_form_alter()
- 7.3 restrict_by_ip.module \restrict_by_ip_form_alter()
Implmentation of hook_form_alter().
File
- ./
restrict_by_ip.module, line 135 - Allows the admin to select which ip addresses role or a user can login from for this site Some of the code below is taken from the cck_ipaddress_module
Code
function restrict_by_ip_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'user_admin_role') {
// Add a custom submit function to handle role deletions.
$form['#submit'][] = 'restrict_by_ip_admin_role_submit';
}
else {
if ($form_id == 'user_profile_form') {
// Add restrict by ip form fields to user add/edit form
global $user;
if (user_access('administer site configuration') || user_access('administer restrict by ip')) {
$uid = $form['#uid'];
drupal_add_css(drupal_get_path('module', 'restrict_by_ip') . '/restrict_by_ip.css', 'module', 'screen', FALSE);
$usrdata_restrict_by_ip_address = "";
// Grab the current restrict by ip data if it exists
$address_entry = db_result(db_query('SELECT restrict_by_ip_address FROM {restrict_by_ip} WHERE uid = %d', $uid));
$form['rip'] = array(
'#type' => 'fieldset',
'#attributes' => array(
'class' => 'restrict-by-ip',
),
'#title' => t('Restrict by IP settings'),
'#weight' => 5,
'#collapsible' => FALSE,
);
$form['rip']['restrict_by_ip_address'] = array(
'#type' => 'textfield',
'#default_value' => $address_entry ? $address_entry : '',
'#maxlength' => 256,
'#description' => t('Enter IP Address Ranges in CIDR Notation seperated with semi-colons, with no trailing semi-colon. E.G. 10.20.30.0/24;192.168.199.1/32;1.0.0.0/8<br />For more information on CIDR notation <a href="http://www.brassy.net/2007/mar/cidr_basic_subnetting" target="_blank">click here</a>.<br /><strong>Leave field empty to disable IP restrictions for this user.</strong>'),
);
$form['#validate'][] = 'restrict_by_ip_user_profile_validate';
$form['#submit'][] = 'restrict_by_ip_user_profile_submit';
}
}
else {
if ($form_id == 'user_register') {
global $user;
if (user_access('administer site configuration') || user_access('administer restrict by ip')) {
drupal_add_css(drupal_get_path('module', 'restrict_by_ip') . '/restrict_by_ip.css', 'module', 'screen', FALSE);
$form['rip'] = array(
'#type' => 'fieldset',
'#attributes' => array(
'class' => 'restrict-by-ip',
),
'#title' => t('Restrict by IP settings'),
'#weight' => 5,
'#collapsible' => FALSE,
);
$form['rip']['restrict_by_ip_address'] = array(
'#type' => 'textfield',
'#default_value' => '',
'#maxlength' => 256,
'#description' => t('Enter IP Address Ranges in CIDR Notation seperated with semi-colons, with no trailing semi-colon. E.G. 10.20.30.0/24;192.168.199.1/32;1.0.0.0/8<br />For more information on CIDR notation <a href="http://www.brassy.net/2007/mar/cidr_basic_subnetting" target="_blank">click here</a>.<br /><strong>Leave field empty to disable IP restrictions for this user.</strong>'),
);
$form['#validate'][] = 'restrict_by_ip_user_register_validate';
}
}
}
}
}