You are here

function ad_text_node_validate in Advertisement 6

Same name and namespace in other branches
  1. 5.2 text/ad_text.module \ad_text_node_validate()
  2. 5 text/ad_text.module \ad_text_node_validate()
  3. 6.3 text/ad_text.module \ad_text_node_validate()
  4. 6.2 text/ad_text.module \ad_text_node_validate()

Text ads node validator.

1 call to ad_text_node_validate()
ad_text_adapi in text/ad_text.module
Implementation of hook_adapi().

File

text/ad_text.module, line 318
Enhances the ad module to support static text ads.

Code

function ad_text_node_validate($node, &$form_state) {

  // Enforce minimum and maximum lengths.
  $header_len = isset($node->adheader) ? strlen($node->adheader) : 0;
  $header_min = variable_get('header_min', 0);
  $header_max = variable_get('header_max', 0);
  if ($header_min && $header_len < $header_min) {
    form_set_error('adheader', t('Your text ad header is only %cur characters but must be at least %min characters.', array(
      '%cur' => $header_len,
      '%min' => $header_min,
    )));
  }
  else {
    if ($header_max && $header_len > $header_max) {
      form_set_error('adheader', t('Your text ad header is %cur characters but can not be more than %max characters.', array(
        '%cur' => $header_len,
        '%max' => $header_max,
      )));
    }
  }
  $body_len = strlen($node->adbody);
  $body_min = variable_get('body_min', 0);
  $body_max = variable_get('body_max', 0);
  if ($body_min && $body_len < $body_min) {
    form_set_error('adbody', t('Your text ad body is only %cur characters but must be at least %min characters.', array(
      '%cur' => $body_len,
      '%min' => $body_min,
    )));
  }
  else {
    if ($body_max && $body_len > $body_max) {
      form_set_error('adbody', t('Your text ad body is %cur characters but can not be more than %max characters.', array(
        '%cur' => $body_len,
        '%max' => $body_max,
      )));
    }
  }
  if ($node->url && variable_get('ad_validate_url', 1) && !valid_url($node->url, TRUE)) {
    form_set_error('url', t('You must specify a valid %field.', array(
      '%field' => t('Destination URL'),
    )));
  }
}