You are here

function _mobile_switch_redirect_url_to_mobile_validate in Mobile Switch 7.2

Render API callback: Validates the redirect URL to mobile.

This function is assigned as an #element_validate callback in mobile_switch_settings_form().

1 string reference to '_mobile_switch_redirect_url_to_mobile_validate'
mobile_switch_settings_form in includes/mobile_switch.admin.inc
Form constructor for the Basic settings form.

File

includes/mobile_switch.admin.inc, line 351
Administrative page callbacks for the Mobile Switch module.

Code

function _mobile_switch_redirect_url_to_mobile_validate($element, &$form_state) {
  if ($form_state['values']['mobile_switch_mobile_theme'] === 'redirect' && empty($element['#value'])) {
    form_error($element, t('%title: The field must contain a value.', array(
      '%title' => t($element['#title']),
    )));
  }
  elseif ($form_state['values']['mobile_switch_mobile_theme'] === 'redirect' && !empty($element['#value'])) {
    $valid_url = valid_url($element['#value'], TRUE);
    if ($valid_url == FALSE) {
      form_error($element, t('%title: The field must contain a URL in a valid format.', array(
        '%title' => t($element['#title']),
      )));
    }
    if ($valid_url == TRUE) {
      if (preg_match('/\\/$/', $element['#value'])) {
        form_error($element, t('%title: Do not use a trailing slash.', array(
          '%title' => t($element['#title']),
        )));
      }
    }
  }
}