You are here

function editor_note_add_note_validate in Editor Notes 7

Validates value of 'Create a note' textarea during adding a note via ajax.

1 string reference to 'editor_note_add_note_validate'
editor_note_field_widget_form in ./editor_note.module
Implements hook_field_widget_form().

File

./editor_note.module, line 1410
Main functionality for Editor Notes module.

Code

function editor_note_add_note_validate(&$form, &$form_state) {
  $field_name = str_replace('_add_note', '', $form_state['triggering_element']['#name']);
  $field_info = field_info_instance($form['#entity_type'], $field_name, $form['#bundle']);
  $field = field_info_field($field_name);
  $note = $form_state['values'][$field_name][LANGUAGE_NONE][0]['note'];
  if (empty($note)) {
    form_set_error($field_name, t('Field %field_name is required.', array(
      '%field_name' => $field_info['label'],
    )));
  }
  if (!empty($note) && $field['settings']['notes_maxlength'] > 0) {
    if (drupal_strlen($note) > $field['settings']['notes_maxlength']) {
      form_set_error($field_name, t('%name: the value cannot not be longer than %max characters.', array(
        '%name' => $field_info['label'],
        '%max' => $field['settings']['notes_maxlength'],
      )));
    }
  }
}