Tripal Plant PopGen Submit
page_2.php File Reference

Go to the source code of this file.

Functions

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

Detailed Description

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

Definition in file page_2.php.

Function Documentation

◆ tpps_page_2_validate_form()

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

Defines the data integrity checks for the second 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_2.php.

16  {
17  if ($form_state['submitted'] == '1') {
18 
19  if (!$form_state['values']['StartingDate']['year']) {
20  form_set_error('StartingDate][year', t('Year: field is required.'));
21  }
22  elseif (!$form_state['values']['StartingDate']['month']) {
23  form_set_error('StartingDate][month', t('Month: field is required.'));
24  }
25 
26  if (!$form_state['values']['EndingDate']['year']) {
27  form_set_error('EndingDate][year', t('Year: field is required.'));
28  }
29  elseif (!$form_state['values']['EndingDate']['month']) {
30  form_set_error('EndingDate][month', t('Month: field is required.'));
31  }
32 
33  if (!$form_state['values']['data_type']) {
34  form_set_error('data_type', t('Data Type: field is required.'));
35  }
36 
37  if (!$form_state['values']['study_type']) {
38  form_set_error('study_type', t('Study Type: field is required.'));
39  }
40 
41  if (!empty($form_state['values']['study_info']['season'])) {
42  foreach ($form_state['values']['study_info']['season'] as $key => $val) {
43  if (!$val) {
44  unset($form_state['values']['study_info']['season'][$key]);
45  }
46  }
47  if (array_key_exists('season', $form_state['values']['study_info']) and empty($form_state['values']['study_info']['season'])) {
48  form_set_error('study_info][season', t('Seasons: field is required.'));
49  }
50  }
51 
52  if (isset($form_state['values']['study_info']['assessions']) and !$form_state['values']['study_info']['assessions']) {
53  form_set_error('study_info][assessions', t('Number of times the populations were assessed: field is required.'));
54  }
55 
56  if (!empty($form_state['values']['study_info']['temp'])) {
57  if (empty($form_state['values']['study_info']['temp']['high'])) {
58  form_set_error('study_info][temp][high', t('Average High Temperature: field is required.'));
59  }
60  if (empty($form_state['values']['study_info']['temp']['low'])) {
61  form_set_error('study_info][temp][low', t('Average Low Temperature: field is required.'));
62  }
63  }
64 
65  $types = array(
66  'co2' => 'CO2',
67  'humidity' => 'Air Humidity',
68  'light' => 'Light Intensity',
69  'salinity' => 'Salinity',
70  );
71 
72  foreach ($types as $type => $label) {
73  if (!empty($form_state['values']['study_info'][$type])) {
74  $set = $form_state['values']['study_info'][$type];
75  if (!$set['option']) {
76  form_set_error("study_info][$type][option", "$label controlled or uncontrolled: field is required.");
77  }
78  elseif ($set['option'] == '1' and !$set['controlled']) {
79  form_set_error("study_info][$type][controlled", "Controlled $label Value: field is required.");
80  }
81  elseif ($set['option'] == '2' and array_key_exists('uncontrolled', $set) and !$set['uncontrolled']) {
82  form_set_error("study_info][$type][uncontrolled", "Average $label Value: field is required.");
83  }
84  }
85  }
86 
87  if (!empty($form_state['values']['study_info']['rooting'])) {
88  $root = $form_state['values']['study_info']['rooting'];
89  if (!$root['option']) {
90  form_set_error("study_info][rooting][option", t("Rooting Type: field is required."));
91  }
92  elseif ($root['option'] == 'Soil') {
93  if (!$root['soil']['type']) {
94  form_set_error('study_info][rooting][soil][type', t('Soil Type: field is required.'));
95  }
96  elseif ($root['soil']['type'] == 'Other' and !$root['soil']['other']) {
97  form_set_error('study_info][rooting][soil][other', t('Custom Soil Type: field is required.'));
98  }
99 
100  if (!$root['soil']['container']) {
101  form_set_error('study_info][rooting][soil][type', t('Soil Container Type: field is required.'));
102  }
103  }
104 
105  $ph = $root['ph'];
106  if (!$ph['option']) {
107  form_set_error("study_info][rooting][ph][option", t("pH controlled or uncontrolled: field is required."));
108  }
109  elseif ($ph['option'] == '1' and !$ph['controlled']) {
110  form_set_error("study_info][rooting][ph][controlled", t("Controlled pH Value: field is required."));
111  }
112  elseif ($ph['option'] == '2' and array_key_exists('uncontrolled', $ph) and !$ph['uncontrolled']) {
113  form_set_error("study_info][rooting][ph][uncontrolled", t("Average pH Value: field is required."));
114  }
115 
116  $selected = FALSE;
117  $description = FALSE;
118 
119  foreach ($root['treatment'] as $field => $value) {
120  if (!$description) {
121  $description = TRUE;
122  $selected = $value;
123  continue;
124  }
125  elseif ($selected and !$value) {
126  form_set_error("study_info][rooting][treatment][$field", t("@field: field is required.", array('@field' => $field)));
127  }
128  $description = FALSE;
129  }
130  }
131 
132  if (!empty($form_state['values']['study_info']['irrigation'])) {
133  $irrigation = $form_state['values']['study_info']['irrigation'];
134  if (!$irrigation['option']) {
135  form_set_error('study_info][irrigation][option', t('Irrigation Type: field is required.'));
136  }
137  elseif ($irrigation['option'] == 'Other' and !$irrigation['other']) {
138  form_set_error('study_info][irrigation][other', t('Custom Irrigation Type: field is required.'));
139  }
140  }
141 
142  if (!empty($form_state['values']['study_info']['biotic_env']) and preg_match('/^0+$/', implode('', $form_state['values']['study_info']['biotic_env']['option']))) {
143  form_set_error('study_info][biotic_env', t('Biotic Environment: field is required.'));
144  }
145  elseif (!empty($form_state['values']['study_info']['biotic_env']['option']['Other']) and !$form_state['values']['study_info']['biotic_env']['other']) {
146  form_set_error('study_info][biotic_env][other', t('Custom Biotic Environment: field is required.'));
147  }
148 
149  if (!empty($form_state['values']['study_info']['treatment']) and $form_state['values']['study_info']['treatment']['check']) {
150  $treatment = $form_state['values']['study_info']['treatment'];
151  $selected = FALSE;
152  $description = FALSE;
153  $treatment_empty = TRUE;
154 
155  foreach ($treatment as $field => $value) {
156  if ($field != 'check') {
157  if (!$description) {
158  $description = TRUE;
159  $selected = $value;
160  if ($value) {
161  $treatment_empty = FALSE;
162  }
163  continue;
164  }
165  elseif ($selected and !$value) {
166  form_set_error("study_info][treatment][$field", t("@field: field is required.", array('@field' => $field)));
167  }
168  $description = FALSE;
169  }
170  }
171 
172  if ($treatment_empty) {
173  form_set_error("study_info][treatment", t('Treatment: field is required.'));
174  }
175  }
176  }
177 }