CodeIgniter Forums
Form Validation Issue - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: Issues (https://forum.codeigniter.com/forumdisplay.php?fid=19)
+--- Thread: Form Validation Issue (/showthread.php?tid=66286)



Form Validation Issue - krishg - 10-03-2016

Migrating from CI 2.x to 3.0. This form validation issue is tripping me. Here is what I have i

Code:
if(!isset($_POST['event_create'])){
            $this->form_validation->set_rules('url', 'URL', 'required|alpha_dash');
            $this->form_validation->set_rules('dateStart', 'Event Date', 'required|regex_match[/([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})/]');
            $this->form_validation->set_rules('timeStart', 'Event Start Time', 'required|regex_match[/^(?=\d)(?:(?!(?:1582(?:\.|-|\/)10(?:\.|-|\/)(?:0?[5-9]|1[0-4]))|(?:1752(?:\.|-|\/)0?9(?:\.|-|\/)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\.|-|\/)(?:29|30))))(\d{4})([-\/.])(0?\d|1[012])\2((?!00)[012]?\d|3[01])(?:$|(?=\x20\d)\x20))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2}(?:\x20[aApP][mM]))|(?:[01]\d|2[0-3])(?::[0-5]\d){1,2})?$/]');
            $this->form_validation->set_rules('timeEnd', 'Event End Time', 'regex_match[/^(?=\d)(?:(?!(?:1582(?:\.|-|\/)10(?:\.|-|\/)(?:0?[5-9]|1[0-4]))|(?:1752(?:\.|-|\/)0?9(?:\.|-|\/)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\.|-|\/)(?:29|30))))(\d{4})([-\/.])(0?\d|1[012])\2((?!00)[012]?\d|3[01])(?:$|(?=\x20\d)\x20))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2}(?:\x20[aApP][mM]))|(?:[01]\d|2[0-3])(?::[0-5]\d){1,2})?$/]');
            $this->form_validation->set_rules('email', 'Email', 'valid_email');
}
The error message I get is 
Unable to access an error message corresponding to your field name Event Start Time.(regex_match[/^(?=\d)(?Sad?!(?:1582(?:\.)
Unable to access an error message corresponding to your field name Event End Time.(regex_match[/^(?=\d)(?Sad?!(?:1582(?:\.)
Worked fine with CI 2.1. 
xss filter flag is set to true. I have checked that we are not using xss_clean in form_validation->set_rules.

Code:
$config['global_xss_filtering'] = TRUE;

I added $autoload['helper'] = array('security') so, my autoload.php for helpers looks like this


Code:
$autoload['helper'] = array('form', 'url', 'utility' );
$autoload['helper'] = array('security');


This change prevented the error message from displaying on form validation, but resulted in new errors

Severity: Error
Message: Call to undefined function url_title()
Filename: controllers/Events.php
Line Number: 756
Fatal error: Call to undefined function base_url() in /var/www/html/application/views/errors/html/error_php.php on line 10

edit: Looking at the logs I found this 
Code:
INFO - 2016-10-03 17:31:40 --> Language file loaded: language/english/form_validation_lang.php
DEBUG - 2016-10-03 17:31:40 --> Unable to find validation rule: regex_match[/^(?=\d)(?:(?!(?:1582(?:\.
ERROR - 2016-10-03 17:31:40 --> Could not find the language line "form_validation_regex_match[/^(?=\d)(?:(?!(?:1582(?:\."
DEBUG - 2016-10-03 17:31:40 --> Unable to find validation rule: regex_match[/^(?=\d)(?:(?!(?:1582(?:\.
ERROR - 2016-10-03 17:31:40 --> Could not find the language line "form_validation_regex_match[/^(?=\d)(?:(?!(?:1582(?:\."

I went ahead and added this to system\language\english\form_validation_lang.php

$lang['form_validation_regex_match'] = 'The {field} must be a valid time';

No change. 

Curious thing is that the error message in the log is not displaying the complete regex pattern

Any ideas?


RE: Form Validation Issue - InsiteFX - 10-03-2016

Are you missing the ending / slash on both of your regex_match?


RE: Form Validation Issue - krishg - 10-03-2016

(10-03-2016, 06:14 PM)InsiteFX Wrote: Are you missing the ending / slash on both of your regex_match?

Don't think so. It's there after the $ sign.  It worked just fine in CI 2.0.


RE: Form Validation Issue - krishg - 10-03-2016

FWIW, I used a callback function for the form validation. That does not get called as well. I get this in the log file

DEBUG - 2016-10-03 21:05:35 --> Unable to find callback validation rule: datetime_check
ERROR - 2016-10-03 21:05:35 --> Could not find the language line "form_validation_datetime_check"


RE: Form Validation Issue - krishg - 10-03-2016

(10-03-2016, 09:24 PM)krishg Wrote: FWIW, I used a callback function for the form validation. That does not get called as well. I get this in the log file

DEBUG - 2016-10-03 21:05:35 --> Unable to find callback validation rule: datetime_check
ERROR - 2016-10-03 21:05:35 --> Could not find the language line "form_validation_datetime_check"

Looks like we have a custom validation form. I put the callback function there and it's getting called there.


RE: Form Validation Issue - InsiteFX - 10-04-2016

All Controller, Libraries and Model files have to have the first character upper case.