function tripal_pub_search_form_validate

2.x tripal_pub.pub_search.inc tripal_pub_search_form_validate($form, &$form_state)
1.x pub_search.inc tripal_pub_search_form_validate($form, &$form_state)

Validate the tripal_pub_search_form form

Related topics

File

tripal_pub/includes/tripal_pub.pub_search.inc, line 388
Functions responsible for creating the publication search form that allows a user of the site to search for publications that are currently in Chado.

Code

function tripal_pub_search_form_validate($form, &$form_state) {
  $num_criteria = $form_state['storage']['num_criteria'];
  $from_year = $form_state['values']['from_year'];
  $to_year = $form_state['values']['to_year'];
  $op = $form_state['values']['op'];

  // no need to vlaidate on a reset
  if ($op == 'Reset') {
    return;
  }

  if ($from_year and !$to_year) {
    form_set_error('to_year', 'Please provide a 4-digit year.');
  }
  if (!$from_year and $to_year) {
    form_set_error('from_year', 'Please provide a 4-digit year.');
  }
  if ($from_year and !preg_match('/\d\d\d\d/', $from_year)) {
    form_set_error('from_year', 'Please provide a 4-digit year.');
  }
  if ($to_year and !preg_match('/\d\d\d\d/', $to_year)) {
    form_set_error('to_year', 'Please provide a 4-digit year.');
  }
}