You are here

function better_messages_admin_skin_form_validate in Better Messages 7.2

Form validation handler for the main Better Messages settings administration form.

See also

better_messages_admin_form()

File

./better_messages.admin.inc, line 386

Code

function better_messages_admin_skin_form_validate($form, &$form_state) {
  $numeric_fields = array(
    'space_x',
    'space_y',
    'open_delay',
    'autoclose_seconds',
  );
  foreach ($numeric_fields as $field_name) {
    if (!is_numeric($form_state['values'][$field_name])) {
      form_set_error($field_name, t('Value must be numerical.'));
    }
  }
  $percentage_width = str_replace('%', '', $form_state['values']['width']);
  $pixels_width = str_replace('px', '', $form_state['values']['width']);
  if (!(is_numeric($percentage_width) xor is_numeric($pixels_width))) {
    form_set_error('width', t('Width is invalid. Make sure you use only px or % suffix.'));
  }
  $popup_allowed_str = array(
    'slow',
    'normal',
    'fast',
  );
  if (in_array($form_state['values']['popin_duration'], $popup_allowed_str) xor !is_numeric($form_state['values']['popin_duration'])) {
    form_set_error('popin_duration', t('Duration of (show) effect is invalid.'));
  }
  if (in_array($form_state['values']['popout_duration'], $popup_allowed_str) xor !is_numeric($form_state['values']['popout_duration'])) {
    form_set_error('popout_duration', t('Duration of (close) effect is invalid.'));
  }
}