From 30784a6d7ffea4b01380847ddfb06bf464f60d4b Mon Sep 17 00:00:00 2001 From: Gareth Sime Date: Mon, 21 Aug 2023 21:08:45 +1200 Subject: [PATCH] Require author and translator dates are numeric This goes some way to addressing issue #154 -- users won't be able to enter non-numeric dates, which is unfortunate, but it does mean that they'll get a proper error message instead of the random server error that they get right now. For the more technical explanation -- When we save the form generation, that all goes into the `form_generators` table. Any new authors that are created as part of the generator are saved into `form_generators_authors`, which has the `auth_yob` and `auth_yod` columns as four-digit integers. This doesn't align well with the actual `authors` table, which allows pretty much anything (`varchar(10)`), and I have no idea how people specify AD vs. BCE using the generator. I don't know enough about how the table is used to know whether we should consider migrating it to `varchar(10)` to match `authors`, but having the two consistent with each other would be good probably. I also tried specifying the input fields as numeric in the HTML, but that didn't quite have the desired effect -- it would just submit the field as empty if it wasn't right, which meant we'd silently drop the data rather than get a validation error. --- application/controllers/public/Project_launch.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/application/controllers/public/Project_launch.php b/application/controllers/public/Project_launch.php index 81892e55..b82991d7 100644 --- a/application/controllers/public/Project_launch.php +++ b/application/controllers/public/Project_launch.php @@ -209,15 +209,15 @@ private function _validate_form() $this->form_validation->set_rules('auth_id[]', 'Author id', 'trim|xss_clean'); $this->form_validation->set_rules('auth_first_name[]', 'lang:proj_launch_auth_first_name', 'trim|xss_clean'); $this->form_validation->set_rules('auth_last_name[]', 'lang:proj_launch_auth_last_name', 'trim|xss_clean'); - $this->form_validation->set_rules('auth_yob[]', 'lang:proj_launch_auth_dob', 'trim|xss_clean'); - $this->form_validation->set_rules('auth_yod[]', 'lang:proj_launch_auth_dod', 'trim|xss_clean'); + $this->form_validation->set_rules('auth_yob[]', 'lang:proj_launch_auth_dob', 'trim|xss_clean|numeric'); + $this->form_validation->set_rules('auth_yod[]', 'lang:proj_launch_auth_dod', 'trim|xss_clean|numeric'); $this->form_validation->set_rules('link_to_auth[]', 'lang:proj_launch_link_to_auth', 'trim|xss_clean|prep_url'); $this->form_validation->set_rules('trans_id[]', 'Translator id', 'trim|xss_clean|numeric'); $this->form_validation->set_rules('trans_first_name[]', 'lang:proj_launch_auth_first_name', 'trim|xss_clean'); $this->form_validation->set_rules('trans_last_name[]', 'lang:proj_launch_auth_last_name', 'trim|xss_clean'); - $this->form_validation->set_rules('trans_yob[]', 'lang:proj_launch_trans_dob', 'trim|xss_clean'); - $this->form_validation->set_rules('trans_yod[]', 'lang:proj_launch_trans_dod', 'trim|xss_clean'); + $this->form_validation->set_rules('trans_yob[]', 'lang:proj_launch_trans_dob', 'trim|xss_clean|numeric'); + $this->form_validation->set_rules('trans_yod[]', 'lang:proj_launch_trans_dod', 'trim|xss_clean|numeric'); $this->form_validation->set_rules('link_to_trans[]', 'lang:proj_launch_link_to_trans', 'trim|xss_clean'); $this->form_validation->set_rules('project_type', 'lang:proj_launch_type_of_project', 'trim|xss_clean|alpha_dash');