You are here

function ip_ranges_form_submit in IP Ranges 7

Same name and namespace in other branches
  1. 7.2 ip_ranges.admin.inc \ip_ranges_form_submit()

Form submission handler for ip_ranges_form().

1 string reference to 'ip_ranges_form_submit'
ip_ranges_form in ./ip_ranges.admin.inc
Defines the form for banning IP addresses.

File

./ip_ranges.admin.inc, line 97
Page callback file for the ip ranges module.

Code

function ip_ranges_form_submit($form, &$form_state) {
  $ip_start = trim($form_state['values']['ip_start']);
  $ip_start = preg_replace('/\\s+/', '', $ip_start);
  $ip = $ip_start;
  if ($form_state['values']['ip_end']) {
    $ip_end = trim($form_state['values']['ip_end']);
    $ip_end = preg_replace('/\\s+/', '', $ip_end);
    $ip .= '-' . $ip_end;
  }
  $type = $form_state['values']['type'];
  db_insert('ip_ranges')
    ->fields(array(
    'ip' => $ip,
    'type' => $type,
  ))
    ->execute();
  $list = $type == 'blacklist' ? 'blacklisted' : 'whitelisted';
  drupal_set_message(t('The IP address %ip has been %list.', array(
    '%ip' => $ip,
    '%list' => $list,
  )));
  $form_state['redirect'] = 'admin/config/people/ip-ranges';
  return;
}