You are here

function dnd_admin_form_validate in Scald: Media Management made easy 7

Validate callback for dnd_admin_form().

Ensure that width and height are numeric values.

File

modules/library/dnd/dnd.admin.inc, line 73
Provides the administration related parts of the DnD module.

Code

function dnd_admin_form_validate($form, &$form_state) {
  if (!is_numeric($form_state['values']['dnd_modal_width'])) {
    form_set_error('dnd_modal_width', t('Width value must be numeric.'));
  }
  if (!is_numeric($form_state['values']['dnd_modal_height'])) {
    form_set_error('dnd_modal_height', t('Height value must be numeric.'));
  }
  $width = (double) $form_state['values']['dnd_modal_width'];
  $height = (double) $form_state['values']['dnd_modal_height'];
  if ($width < 0) {
    form_set_error('dnd_modal_width', t('Width value must be bigger than zero.'));
  }
  if ($height < 0) {
    form_set_error('dnd_modal_height', t('Height value must be bigger than zero.'));
  }
  if ($width <= 1 && $height > 1 || $width > 1 && $height <= 1) {
    form_set_error('dnd_modal_width', t('Width and height values must both be in the same metric.'));
  }
}