Jump to content


custom message when use set_rules


  • Please log in to reply
1 reply to this topic

#1 hunter205

hunter205

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 09 June 2019 - 08:43 AM

I tried to validate input time as hh:ss by regex, but it didn't work. can anyone show me my mistake????? it seems callback function in set_rules() didn't work.
 
set_rule() as follow:
 /* VALIDATE START TIME - END TIME in hh:ss format */
        /* /^([01]?[0-9]|2[0-3]):[0-5][0-9]$/ */
        $crud->set_rules('startTime', 'Begin Time', 'callback_test_check(' . $this->input->post('startTime') . ')');

and this is callback function:

function test_check($str) {
        if (!preg_match('/^([01]?[0-9]|2[0-3]):[0-5][0-9]$/', $str)) {   
            $this->form_validation->set_message('test_check', 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.');
            return false;
        }
        return true;
    }

And it's always throw this message although i tried many times.

Unable to access an error message corresponding to your field name Begin Time.(test_check(22:22))

Attached Thumbnails

  • Capture.PNG


#2 hunter205

hunter205

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 09 June 2019 - 12:56 PM

oh i found it. i did wrong syntax @@  this is worked 

/* VALIDATE START TIME - END TIME in hh:ss format */
/* /^([01]?[0-9]|2[0-3]):[0-5][0-9]$/ */
$crud->set_rules('startTime', 'Begin Time', 'callback_validate_time_format');

and 

function validate_time_format($str) {
        if (!preg_match('/^([01]?[0-9]|2[0-3]):[0-5][0-9]$/', $str)) {
            $this->form_validation->set_message('validate_time_format', 'The {field} is not in the correct format (hh:ss).');
            return false;
        }
        return true;
    }

however, i don't know why following code "regex_match" of grocery, does't work... so i need to do more as above

$crud->set_rules('startTime', 'Begin Time', 'regex_match[/^([01]?[0-9]|2[0-3]):[0-5][0-9]$/]');

Attached Thumbnails

  • 222.JPG





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users