Welcome Guest, Not a member yet? Register   Sign In
SOLVED: Callbacks and form_validation.php
#1

[eluser]gigas10[/eluser]
Hey there,

I'm having a bit of trouble understanding how callbacks work when you are using the form_validation.php file.

Currently this is what I have in my form_validation.php file (at least the important part):
Code:
array(
         'field'   => 'lot_number',
         'label'   => 'Lot Number',
         'rules'   => 'trim|required|xss_clean|prep_for_form|callback_validLotNumber'
    ),

and this is at the bottom of the form_validation.php file:
Code:
function validLotNumber($field){
    if(!preg_match("/^([a-z]{4}&[0-9]{1,100})&/", strtolower($field))){
        $this->form_validation->set_message('lot_number', 'The Lot Number field did not match the pattern 4 letters followed by any amount of integers');
        return false;
    }
    return true;
}

First of all, does my callback function belong in the form_validation.php file? And if it does not, where does it go? Thanks for the help.

My code is not currently working, everything but the callback works. Maybe I'm doing something wrong with the regex? Maybe you have to have some special thing enabled in php to use preg_match? I'm unsure with regular expressions completely, so any help is much appreciated.


Messages In This Thread
SOLVED: Callbacks and form_validation.php - by El Forum - 01-07-2010, 10:08 AM
SOLVED: Callbacks and form_validation.php - by El Forum - 01-07-2010, 10:31 AM
SOLVED: Callbacks and form_validation.php - by El Forum - 01-07-2010, 10:44 AM
SOLVED: Callbacks and form_validation.php - by El Forum - 01-07-2010, 12:22 PM



Theme © iAndrew 2016 - Forum software by © MyBB