You are here

public function IPRangesFormController::submit in IP Ranges 8

File

lib/Drupal/ip_ranges/IPRangesFormController.php, line 138

Class

IPRangesFormController

Namespace

Drupal\ip_ranges

Code

public function submit(array $form, array &$form_state) {
  $ip_lower =& $form_state['values']['ip_lower'];
  $ip_higher =& $form_state['values']['ip_higher'];
  $ip_lower = trim($ip_lower);
  $ip_higher = trim($ip_higher);

  // We're dealing with ranges so let's create an artificial range if
  // there is no specified higher bound.
  if (empty($form_state['values']['ip_higher'])) {
    $ip_higher = $ip_lower;
  }

  // Convert the IP address strings into a proper address. Use sprintf to
  // get the string representation of the unsigned IP address.
  $ip_lower = sprintf("%u", ip2long($ip_lower));
  $ip_higher = sprintf("%u", ip2long($ip_higher));

  // If the higher and lower IPs are in fact lower and higher, let's swap
  // them prior to database insertion.
  if ($ip_lower > $ip_higher) {
    $temp = $ip_lower;
    $ip_lower = $ip_higher;
    $ip_higher = $temp;
  }
  parent::submit($form, $form_state);
}