Tripal Plant PopGen Submit
page_1.php File Reference

Go to the source code of this file.

Functions

 tpps_page_1_validate_form (array &$form, array &$form_state)
 

Detailed Description

Defines the data integrity checks for the first page of the form.

Definition in file page_1.php.

Function Documentation

◆ tpps_page_1_validate_form()

tpps_page_1_validate_form ( array &  $form,
array &  $form_state 
)

Defines the data integrity checks for the first page of the form.

Parameters
array$formThe form that is being validated.
array$form_stateThe state of the form that is being validated.

Definition at line 16 of file page_1.php.

16  {
17  if ($form_state['submitted'] == '1') {
18  unset($form_state['file_info'][TPPS_PAGE_1]);
19 
20  $form_values = $form_state['values'];
21  $primary_author = $form_values['primaryAuthor'];
22  $organization = $form_values['organization'];
23  $publication_status = $form_values['publication']['status'];
24  $second = $form_values['publication']['secondaryAuthors'];
25  $second_num = $second['number'];
26  $year = $form_values['publication']['year'];
27  $publication_title = $form_values['publication']['title'];
28  $publication_abstract = $form_values['publication']['abstract'];
29  $publication_journal = $form_values['publication']['journal'];
30  $organism = $form_values['organism'];
31  $organism_number = $form_values['organism']['number'];
32 
33  if ($primary_author == '') {
34  form_set_error('primaryAuthor', t('Primary Author: field is required.'));
35  }
36 
37  if ($organization == '') {
38  form_set_error('organization', t('Organization: field is required.'));
39  }
40 
41  if (!$publication_status) {
42  form_set_error('publication][status', t('Publication Status: field is required.'));
43  }
44 
45  if ($second_num > 0) {
46  for ($i = 1; $i <= $second_num; $i++) {
47  if (empty($second[$i])) {
48  form_set_error("publication][secondaryAuthors][$i", t("Secondary Author @i: field is required.", array('@i' => $i)));
49  }
50  }
51  }
52 
53  if (!$year) {
54  form_set_error('publication][year', t('Year of Publication: field is required.'));
55  }
56 
57  if ($publication_title == '') {
58  form_set_error('publication][title', t('Title of Publication: field is required.'));
59  }
60 
61  if ($publication_abstract == '') {
62  form_set_error('publication][abstract', t('Abstract: field is required.'));
63  }
64 
65  if ($publication_journal == '') {
66  form_set_error('publication][journal', t('Journal: field is required.'));
67  }
68 
69  for ($i = 1; $i <= $organism_number; $i++) {
70  $name = $organism[$i]['name'];
71 
72  if ($name == '') {
73  form_set_error("organism[$i][name", "Plant Species $i: field is required.");
74  }
75  else {
76  $name = explode(" ", $name);
77  $genus = $name[0];
78  $species = implode(" ", array_slice($name, 1));
79  $name = implode(" ", $name);
80  $empty_pattern = '/^ *$/';
81  $correct_pattern = '/^[A-Z|a-z|.| ]+$/';
82  if (!isset($genus) or !isset($species) or preg_match($empty_pattern, $genus) or preg_match($empty_pattern, $species) or !preg_match($correct_pattern, $genus) or !preg_match($correct_pattern, $species)) {
83  form_set_error("organism[$i][name", check_plain("Plant Species $i: please provide both genus and species in the form \"<genus> <species>\"."));
84  }
85  }
86  }
87  }
88 }
const TPPS_PAGE_1
Definition: tpps.module:12