You are here

function imagepicker_copy_form_validate in Image Picker 6.2

Same name and namespace in other branches
  1. 7 imagepicker.functions.inc \imagepicker_copy_form_validate()

Function to validate the copy form

File

./imagepicker.functions.inc, line 2646
Imagepicker functions

Code

function imagepicker_copy_form_validate($form, &$form_state) {
  if (!drupal_strlen($form_state['values']['imagepicker_copy'])) {
    form_set_error('imagepicker_copy', t('You must supply a name'));
  }
  elseif (!preg_match('/^[a-zA-Z0-9_ .-]+$/', $form_state['values']['imagepicker_copy'])) {
    form_set_error('imagepicker_copy', t('You must supply a valid name'));
  }
  if ($form_state['values']['uid']) {
    $user = user_load(array(
      'uid' => $form_state['values']['uid'],
    ));
  }
  else {
    global $user;
  }
  $img_id = $form_state['values']['img_id'];
  $img = _imagepicker_get_img($img_id, TRUE, $user);
  preg_match('/\\.([a-zA-Z]+)$/', $img['img_name'], $m);
  $oldext = $m[1];
  preg_match('/\\.([a-zA-Z]+)$/', $form_state['values']['imagepicker_copy'], $m);
  $newext = $m[1];
  if ($oldext != $newext) {
    form_set_error('imagepicker_copy', t('You must use the same extension'));
  }
  if ($img['img_name'] == $form_state['values']['imagepicker_copy']) {
    form_set_error('imagepicker_copy', t('You cannot copy a file onto itself'));
  }
  if (!preg_match('/^[0-9]{0,3}$/', $form_state['values']['scale'])) {
    form_set_error($name, t('Scale value should be an integer between 1 and 999 or leave it empty if you don\'t want to scale your image.'));
  }
}