You are here

function user_badges_edit_form_validate in User Badges 7.3

Same name and namespace in other branches
  1. 6.2 user_badges.admin.inc \user_badges_edit_form_validate()
  2. 6 user_badges.admin.inc \user_badges_edit_form_validate()
  3. 7 user_badges.admin.inc \user_badges_edit_form_validate()
  4. 7.2 user_badges.admin.inc \user_badges_edit_form_validate()

Validate user_badges_edit_form form submissions.

File

./user_badges.admin.inc, line 437
@brief User Badges admin functions

Code

function user_badges_edit_form_validate($form, &$form_state) {

  // Verify that the user has provided the required information based
  // upon the image location choosen.
  $image_location = $form_state['values']['image_location'];
  if ($image_location == 'external') {
    if (!$form_state['values']['imageurl']) {
      form_set_error('imageurl', t('You must enter an image URL.'));
    }
    elseif (!valid_url($form_state['values']['imageurl'], TRUE)) {

      // The image URL must also be a valid url.
      form_set_error('imageurl', t('This is not a valid image URL. You need to enter a complete image URL, including the "http://" at the start.'));
    }
  }
  elseif ($image_location == 'upload' && !$form_state['values']['imagefile']) {
    form_set_error('imagefile', t('You need to upload a local file.'));
  }
  elseif ($image_location == 'library' && empty($form_state['values']['imagefromlibrary'])) {
    form_set_error('imagelibrary', t('Your library is empty, please upload a file.'));
  }

  // Weights must be numeric.
  if (!is_numeric($form_state['values']['weight'])) {
    form_set_error('weight', t('Your value for the weight must be a number. Negative numbers are allowed, but not decimals.'));
  }
}