You are here

function imagecrop_validate_offset in Image javascript crop 7

Validation function to validate an entered offset value. (numbers or left / center / right)

1 string reference to 'imagecrop_validate_offset'
imagecrop_effect_form in includes/imagecrop.effects.inc
Settings form for configuring a javascript imagecrop effect.

File

includes/imagecrop.effects.inc, line 184
Registry for the image style effects from imagecrop.

Code

function imagecrop_validate_offset($element, &$form_state) {
  if ($element['#value'] == '') {
    return;
  }

  // numbers are allowed.
  if (is_numeric($element['#value'])) {
    return;
  }
  if ($element['#name'] == 'data[yoffset]') {
    $allowed_values = array(
      'center',
      'top',
      'bottom',
    );
  }
  else {
    $allowed_values = array(
      'center',
      'left',
      'right',
    );
  }

  // if the value is a string, check on allowed strings
  if (!in_array($element['#value'], $allowed_values)) {
    form_error($element, t('@name must be a correct offset value', array(
      '@name' => $element['#title'],
    )));
  }
}