You are here

function mobile_navigation_displays_form_validate in Mobile Navigation 7.2

File

./mobile_navigation.admin.inc, line 354
Mobile Navigation Administration page.

Code

function mobile_navigation_displays_form_validate($form, &$form_state) {
  if (isset($form_state['values']['display_actions'])) {
    $displays_actions = $form_state['values']['display_actions'];
    foreach ($displays_actions as $ii => $da) {
      $bottom = $da["bottom"];
      $top = $da["top"];
      if ($da["media_query"] == "" and $bottom == "" and $top == "") {
        form_set_error('', t('All displays in the list must have a value for top or bottom limits or a media query defined.'));
      }
      if (strlen(trim($bottom)) > 0) {
        if (!is_numeric($bottom)) {
          form_set_error('display_actions', t('Bottom values on Query definitions must be numeric.'));
        }
      }
      if (strlen(trim($top)) > 0) {
        if (!is_numeric($top)) {
          form_set_error('display_actions', t('Top values on Query definitions must be numeric.'));
        }
      }
    }
  }
  if ($form_state['values']['mobile_navigation_display_name'] != "" and $form_state['values']['mobile_navigation_bottom'] == "" and $form_state['values']['mobile_navigation_top'] == "" and $form_state['values']['mobile_navigation_media_query'] == '') {
    form_set_error('mq', t('You entered a name for a new display, however no Media Query definition was specified. Please enter a value for top or bottom limits or a media query definition.'));
  }
  if ($form_state['values']['mobile_navigation_display_name'] == "" and ($form_state['values']['mobile_navigation_bottom'] != '' or $form_state['values']['mobile_navigation_top'] != '' or $form_state['values']['mobile_navigation_media_query'] != '')) {
    form_set_error('mobile_navigation_display_name', t('You entered values for a Media Query definition, however you didn\'t specify a display name. Please specify a name for the display you want to create.'));
  }
  $bottom = $form_state['values']['mobile_navigation_bottom'];
  if (strlen(trim($bottom)) > 0) {
    if (!is_numeric($bottom)) {
      form_set_error('mobile_navigation_bottom', t('Bottom values on Query definitions must be numeric.'));
    }
  }
  $top = $form_state['values']['mobile_navigation_top'];
  if (strlen(trim($top)) > 0) {
    if (!is_numeric($top)) {
      form_set_error('mobile_navigation_top', t('Top values on Query definitions must be numeric.'));
    }
  }
  $name = $form_state['values']['mobile_navigation_display_name'];
  if ($name != '') {

    /* Check for duplicated name */
    $displays = get_displays_list();
    while ($row = $displays
      ->fetchAssoc()) {
      $ds_name = $row['name'];
      if ($name == $ds_name) {
        form_set_error('mobile_navigation_name', t('Display name already used. Please choose a different name.'));
      }
    }
  }
}