CodeIgniter Forums
validation help required - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: validation help required (/showthread.php?tid=8074)



validation help required - El Forum - 05-04-2008

[eluser]Computerzworld[/eluser]
Hello. I am having problem in validating my field values using CI validation class. I am having two comboboxes and I want that when user submits the form both the combobox have different value(Value can not be same). How can I do this using CI validation class? Please help me. Thanks in advance.


validation help required - El Forum - 05-04-2008

[eluser]Computerzworld[/eluser]
got the solutionSmile


validation help required - El Forum - 05-05-2008

[eluser]maesk[/eluser]
Hi,

how about posting your code? Otherwise this thread is kinda useless.


validation help required - El Forum - 05-05-2008

[eluser]Computerzworld[/eluser]
Here is the callback function which i have used to compare two combobox's value....

Code:
function stationCheck($str)
    {
        if ($this->input->post("startStation")==$this->input->post("endStation"))
        {
            $this->validation->set_message('stationCheck', 'Start station and end station can not be same');
            return FALSE;
        }
        else
        {
            return TRUE;
        }
    }



validation help required - El Forum - 05-05-2008

[eluser]wiredesignz[/eluser]
Code:
//this is a nicer solution
    function stationCheck()
    {
        $this->validation->set_message('stationCheck', 'Start station and end station can not be same');
        
        return (bool)($this->input->post("startStation") != $this->input->post("endStation"))
    }



validation help required - El Forum - 05-05-2008

[eluser]maesk[/eluser]
Thank you, Computerzworld and wiredesignz for posting the code. I'm sure it'll prove useful for some people. I'm currently using the Validation class for the first time and although the user guide is great, as usual, I'm always glad to have a few examples to learn from.


validation help required - El Forum - 07-09-2008

[eluser]Chillahan[/eluser]
I am curious - do people use the validation class for final values to input into database (or to otherwise process)? I just use input->post once validation->run() returns TRUE - since validation doesn't clean data, I assume it's safe to use input->post (since input class is the one that cleans data anyway).

Also, I would like to note a 'best practice' of mine regarding callback functions - I always keep them prefixed with _. Note that this means in your validation rules, when you assign the validation rule, it needs to have two underscores, not just one as in the User Guide examples (i.e., __data_check, not _data_check). If you do NOT do this, then you're basically exposing that callback function for public access! Imagine what you're opening up to a hacker anytime you start a new function in a controller file - do not forget this! For example, if you have a validation to check validity of some data, or even worse, to look it up in database, you're opening a wide open hole for a dictionary attack (or at best, a DOS attack on your mySQL daemon).


validation help required - El Forum - 07-09-2008

[eluser]Colin Williams[/eluser]
I usually keep my callbacks private, too.

Also, wiredesignz, you don't even need the (bool) modifier:

Code:
//this is a nicer solution
    function stationCheck()
    {
        $this->validation->set_message('stationCheck', 'Start station and end station can not be same');
        
        return $this->input->post("startStation") != $this->input->post("endStation");
    }