You are here

function lightbox2_general_settings_form_validate in Lightbox2 7

Same name and namespace in other branches
  1. 8 lightbox2.admin.inc \lightbox2_general_settings_form_validate()
  2. 5.2 lightbox2.module \lightbox2_general_settings_form_validate()
  3. 6 lightbox2.admin.inc \lightbox2_general_settings_form_validate()
  4. 7.2 lightbox2.admin.inc \lightbox2_general_settings_form_validate()

Validation function for the general configuration form.

Ensure that the hex color value submitted is valid and that the speeds are numeric.

File

./lightbox2.admin.inc, line 508
Administrative page callbacks for the lightbox2 module.

Code

function lightbox2_general_settings_form_validate($form, &$form_state) {
  if ($form_state['values']['op'] == t('Save configuration')) {
    $border_size = $form_state['values']['lightbox2_border_size'];
    $box_hex_colour = $form_state['values']['lightbox2_box_color'];
    $font_hex_colour = $form_state['values']['lightbox2_font_color'];
    $top_position = $form_state['values']['lightbox2_top_position'];
    $overlay_hex_colour = $form_state['values']['lightbox2_overlay_color'];
    $resize_speed = $form_state['values']['lightbox2_resize_speed'];
    $fadein_speed = $form_state['values']['lightbox2_fadein_speed'];
    $slide_down_speed = $form_state['values']['lightbox2_slidedown_speed'];
    $flv_player_path = $form_state['values']['lightbox2_flv_player_path'];
    if (!empty($flv_player_path) && $form_state['values']['lightbox2_enable_video']) {
      if (strpos($flv_player_path, base_path()) === 0) {
        $flv_player_path = drupal_substr($flv_player_path, drupal_strlen(base_path()));
      }
      if (!file_exists($flv_player_path)) {
        form_set_error('lightbox2_flv_player_path', t("FLV player path doesn't exist."));
      }
    }
    if (!_lightbox2_validate_hex_color($overlay_hex_colour)) {
      form_set_error('lightbox2_overlay_color', t('You must enter a properly formed hex value.'));
    }
    if (!$form_state['values']['lightbox2_lite']) {
      if (!is_numeric($border_size) || $border_size < 0) {
        form_set_error('lightbox2_border_size', t('You must enter a size greater than 0 pixels.'));
      }
      if (!_lightbox2_validate_hex_color($box_hex_colour)) {
        form_set_error('lightbox2_box_color', t('You must enter a properly formed hex value.'));
      }
      if (!_lightbox2_validate_hex_color($font_hex_colour)) {
        form_set_error('lightbox2_font_color', t('You must enter a properly formed hex value.'));
      }
      if (!empty($top_position) && (!is_numeric($top_position) || $top_position < 0)) {
        form_set_error('lightbox2_top_position', t('You must enter a size greater than 0 pixels.  Leave blank for default positioning.'));
      }
      if (!is_numeric($resize_speed) || $resize_speed <= 0 || $resize_speed >= 10) {
        form_set_error('lightbox2_resize_speed', t('You must enter a duration between 0 and 10 seconds.'));
      }
      if (!is_numeric($fadein_speed) || $fadein_speed < 0 || $fadein_speed >= 10) {
        form_set_error('lightbox2_fadein_speed', t('You must enter a duration between 0 and 10 seconds.'));
      }
      if (!is_numeric($slide_down_speed) || $slide_down_speed <= 0 || $slide_down_speed >= 10) {
        form_set_error('lightbox2_slidedown_speed', t('You must enter a duration between 0 and 10 seconds.'));
      }
    }
  }
}