You are here

function _iframe_validate in Iframe 6

1 call to _iframe_validate()
iframe_field in ./iframe.module
Implementation of hook_field().

File

./iframe.module, line 306
Defines simple iframe field types. based on the cck-module "link" by quicksketch MODULE-Funtions

Code

function _iframe_validate(&$item, $delta, $field, $node, &$optional_field_found) {
  dmsg(3, 'func _iframe_validate');
  $trimmed_title = trim($item['title']);
  $trimmed_url = trim($item['url']);
  if ($item['url'] && !(isset($field['widget']['default_value'][$delta]['url']) && $item['url'] == $field['widget']['default_value'][$delta]['url'] && !$field['required'])) {

    // Validate the iframe.
    if (iframe_validate_url($trimmed_url) == FALSE) {
      form_set_error($field['field_name'] . '][' . $delta . '][url', t('Not a valid iframe-url.'));
    }

    // Require a title for the iframe if necessary.
    if ($field['title'] == 'required' && empty($trimmed_title)) {
      form_set_error($field['field_name'] . '][' . $delta . '][title', t('Titles are required for all iframes.'));
    }
  }

  // Require a iframe if we have a title.
  if ($field['url'] !== 'optional' && drupal_strlen($item['title']) > 0 && empty($trimmed_url)) {
    form_set_error($field['field_name'] . '][' . $delta . '][url', t('You cannot enter a title without a iframe url.'));
  }

  // In a totally bizzaro case, where URLs and titles are optional but the field is required, ensure there is at least one iframe.
  if ($field['url'] == 'optional' && $field['title'] == 'optional' && (!empty($trimmed_title) || !empty($trimmed_url))) {
    $optional_field_found = TRUE;
  }
}