function restrict_by_ip_form_alter in Restrict Login or Role Access by IP Address 7.3
Same name and namespace in other branches
- 8.4 restrict_by_ip.module \restrict_by_ip_form_alter()
- 6.3 restrict_by_ip.module \restrict_by_ip_form_alter()
Implmentation of hook_form_alter().
File
- ./
restrict_by_ip.module, line 147 - 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_profile_form' || $form_id == 'user_register_form') {
// Add restrict by ip form fields to user add/edit form
if (user_access('administer site configuration') || user_access('administer restrict by ip')) {
$address_entry = '';
if ($form_id == 'user_profile_form') {
$uid = $form['#user']->uid;
$form['#validate'][] = 'restrict_by_ip_user_profile_validate';
$form['#submit'][] = 'restrict_by_ip_user_profile_submit';
$usrdata_restrict_by_ip_address = "";
// Grab the current restrict by ip data if it exists
$address_entry = db_query('SELECT restrict_by_ip_address FROM {restrict_by_ip} WHERE uid = :uid', array(
':uid' => $uid,
))
->fetchField();
}
else {
$form['#validate'][] = 'restrict_by_ip_user_profile_validate';
}
$form['rip'] = array(
'#type' => 'fieldset',
'#attributes' => array(
'class' => array(
'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,
'#maxlength' => NULL,
'#description' => t('Enter IP Address Ranges in CIDR Notation separated 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>'),
);
}
}
}