Welcome Guest, Not a member yet? Register   Sign In
[solved]Custom Validation?
#6

[eluser]Mirge[/eluser]
[quote author="brucebat" date="1312327204"]Sorry

Well for instance I put in a time of this in my form "42:43:60"

It should return a message saying "The %s time fields Hour segment is not correct."

There is just a blank white page.

To test I have this just after my validation:

Code:
$this->form_validation->set_rules('time'.$i, 'Time'.($i+1), 'required|xss_clean|callback_valid_time'); // time0, time1, time2 etc

echo validation_errors();
return;

Using the example I used "$str" which I am guessing is a variable passed to my custom function from the form_validation class?[/quote]

What happens when you remove callback_valid_time from the rules?

Not a blank page?

Seems strange. I copied your code, tested it... and it works as expected. I modified it of course since I tested outside of a CI install... but it gave the expected output:

Code:
<?php

var_dump(valid_time('42:43:60'));

function valid_time($str)
{
    
    //This part seperates the string into three segments using the ":" as the divide
    $parts = explode(':', $str);
    
    //1st validation checks to make sure there are three parts made from string
    if(sizeof($parts) != 3)
    {
        print('The %s fields has too many time segments');
        return FALSE;
    }
    
    else
    {
        //if hours segment is not 24 hour compliant
        if($parts[0] < 24 || $parts[0] >= 0)
        {
            print('The %s fields Hour segment is not correct');
            return FALSE;
        }
        
        //if minutes segment is not 24 hour compliant
        else if($parts[1] < 0 || $parts[1] > 59)
        {
            print('The %s fields Minute segment is not correct');
            return FALSE;
        }
        
        //if seconds segment is not 24 hour compliant
        else if($parts[2] < 0 || $parts[2] > 59)
        {
            // $this->form_validation->set_message('The %s fields Seconds segment is not correct');
            return FALSE;
        }
        
        //validation passed!
        return TRUE;
    }

}

Output: The %s fields Hour segment is not correctbool(false)


perhaps check the value of $i?


Messages In This Thread
[solved]Custom Validation? - by El Forum - 08-02-2011, 10:56 AM
[solved]Custom Validation? - by El Forum - 08-02-2011, 11:36 AM
[solved]Custom Validation? - by El Forum - 08-02-2011, 12:14 PM
[solved]Custom Validation? - by El Forum - 08-02-2011, 12:15 PM
[solved]Custom Validation? - by El Forum - 08-02-2011, 12:20 PM
[solved]Custom Validation? - by El Forum - 08-02-2011, 12:33 PM
[solved]Custom Validation? - by El Forum - 08-02-2011, 01:22 PM
[solved]Custom Validation? - by El Forum - 08-02-2011, 01:28 PM
[solved]Custom Validation? - by El Forum - 08-02-2011, 01:30 PM
[solved]Custom Validation? - by El Forum - 08-02-2011, 01:34 PM
[solved]Custom Validation? - by El Forum - 08-02-2011, 01:35 PM
[solved]Custom Validation? - by El Forum - 08-02-2011, 01:39 PM
[solved]Custom Validation? - by El Forum - 08-02-2011, 01:41 PM
[solved]Custom Validation? - by El Forum - 08-02-2011, 01:43 PM
[solved]Custom Validation? - by El Forum - 08-02-2011, 01:44 PM
[solved]Custom Validation? - by El Forum - 08-02-2011, 01:50 PM
[solved]Custom Validation? - by El Forum - 08-02-2011, 01:53 PM
[solved]Custom Validation? - by El Forum - 08-02-2011, 01:57 PM
[solved]Custom Validation? - by El Forum - 08-02-2011, 01:58 PM
[solved]Custom Validation? - by El Forum - 08-02-2011, 02:13 PM
[solved]Custom Validation? - by El Forum - 08-02-2011, 02:14 PM
[solved]Custom Validation? - by El Forum - 08-02-2011, 02:16 PM
[solved]Custom Validation? - by El Forum - 08-02-2011, 02:18 PM



Theme © iAndrew 2016 - Forum software by © MyBB