You are here

function responsive_preview_validate_device_values in Responsive Theme Preview 7

Validates values in the form that describe a device definition.

Parameters

$form: An associative array containing the structure of the form.

$form_state: An associative array containing the current state of the form.

2 calls to responsive_preview_validate_device_values()
responsive_preview_device_add_form_validate in ./responsive_preview.admin.inc
Form validation handler for responsive_preview_device_add_form().
responsive_preview_device_edit_form_validate in ./responsive_preview.admin.inc
Form validation handler for responsive_preview_device_edit_form().

File

./responsive_preview.admin.inc, line 522
Administrative page callbacks for the responsive_preview module.

Code

function responsive_preview_validate_device_values($form, &$form_state) {
  if (!empty($form_state['values']['device']['label'])) {
    if (!preg_match("/^[a-zA-Z0-9_ ]+\$/", trim($form_state['values']['device']['label']))) {
      form_set_error('device][label', t('The label must contain only alphanumeric characters, underscores and spaces.'));
    }
  }
  foreach ($form_state['values']['device']['dimensions'] as $type => $value) {
    if (!empty($value)) {
      if (!preg_match("/^[0-9\\.]+\$/", trim($value))) {
        form_set_error('device][dimensions][' . $type, t('The @type dimension must contain only numeric characters.', array(
          '@type' => $type,
        )));
      }
    }
  }
}