tfix input check for first part of form - cosmo - front and backend for Markov-Chain Monte Carlo inversion of cosmogenic nuclide concentrations (HTM) git clone git://src.adamsgaard.dk/cosmo (DIR) Log (DIR) Files (DIR) Refs (DIR) README (DIR) LICENSE --- (DIR) commit 18ddcf894fc1a9011f68410e7498fad52c7e8a53 (DIR) parent 7878323ad53576b15722908fd7c3c053abc64319 (HTM) Author: Anders Damsgaard <anders.damsgaard@geo.au.dk> Date: Tue, 18 Aug 2015 13:12:02 +0200 fix input check for first part of form Diffstat: M uploadhistory.php | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) --- (DIR) diff --git a/uploadhistory.php b/uploadhistory.php t@@ -5,22 +5,22 @@ //$missing_fields = ''; // string of missing field names $missing_fields = array(); // array of missing field names +//die('"' . $_POST['sample_id'] . '", ' . isset($_POST['sample_id'])); // Check required fields one by one -if (!isset($_POST['sample_id'])) { +if (!isset($_POST['sample_id']) || $_POST['sample_id'] == '') { array_push($missing_fields, 'Sample ID'); - die('sample_id missing'); } -if (!isset($_POST['your_name'])) { +if (!isset($_POST['your_name']) || $_POST['your_name'] == '') { array_push($missing_fields, 'Your Name'); } -if (!isset($_POST['email'])) { +if (!isset($_POST['email']) || $_POST['email'] == '') { array_push($missing_fields, 'Email'); } -if (!isset($_POST['lat'])) { +if (!isset($_POST['lat']) || $_POST['lat'] == '') { array_push($missing_fields, 'Latitude'); } -if (!isset($_POST['long'])) { +if (!isset($_POST['long']) || $_POST['long'] == '') { array_push($missing_fields, 'Longitude'); } t@@ -29,11 +29,18 @@ if (count($missing_fields) > 0) { $error_msg = '<html><body>' . '<h2>Invalid input</h2>' . '<p>The following values are missing: <b>'; - foreach ($missing_fields as $field) { - $error_msg .= $field . ', '; + // generate comma-separated list of missing field names + for ($i = 0; $i < count($missing_fields); $i++) { + if (1 == count($missing_fields)) { // just a single missing field + $error_msg .= $missing_fields[$i]; + } elseif ($i + 1 == count($missing_fields)) { // no comma for last word + $error_msg .= ' and ' . $missing_fields[$i]; + } else { + $error_msg .= $missing_fields[$i] . ', '; + } } $error_msg .= '</b></p><p>Please <a href="javascript:history.back()">go' . - ' back</a> and fill in the missing field values.</p></body></html>'; + ' back</a> and fill in the missing fields.</p></body></html>'; die($error_msg); // end this script, print error }