• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Callback when using form_validation.php $config array

#1
[eluser]Ickes[/eluser]
Using form_validation.php to store all my rules in one config file as described in the form validation part of the user guide. With normal rules, the file works perfectly fine. Great.

I can't get a custom callback to work properly. This is my first attempt at a callback so bear with me.

The form has a dropdown menu with 3 options. For the sake of argument, 1 = yes, 2 = no, 3 = maybe. These options are stored in a table with table_id = 1 = yes, table_id = 2 = no, table_id = 3 = maybe.

I want a callback that checks if the user choice is within the range of possible choices. That is, if the user somehow spoofed the form and entered 700 as the choice, I want that to fail.

Here is what I have.
Code:
//Part of form_validation.php
//This part is working fine except when I add the callback part
array(
        'field' => 'choice',
    'label' => 'Dropdown Choice',
    'rules' => 'required|is_natural_no_zero|callback_in_domain["tbl_choices"]'                )

Code:
//farther down in the form_validation.php file
function in_domain($form_value, $table_name)
{
    if(isset($table_name))
    {
        $stmt = $dbh->query("SELECT COUNT(*) FROM $table_name");
        $stmt->execute();
        $count = $stmt->fetchColumn();
        if($form_value <= $count)
        {
            return TRUE;
                        exit();
        }
    }
    $this->form_validation->set_message('choice', 'The %s field can not be the word "test"');
    return FALSE;
}

So lets call all of that part 1.
#2 - Can the function be placed in the form_validation.php file or should it be placed in the controller or somewhere else?
#3 - I believe this function should be private to prevent someone from submitting with their own table name - hack attempt

Thanks.


Messages In This Thread
Callback when using form_validation.php $config array - by El Forum - 07-14-2009, 01:17 PM
Callback when using form_validation.php $config array - by El Forum - 07-14-2009, 01:23 PM
Callback when using form_validation.php $config array - by El Forum - 07-14-2009, 01:33 PM
Callback when using form_validation.php $config array - by El Forum - 07-14-2009, 01:39 PM
Callback when using form_validation.php $config array - by El Forum - 07-14-2009, 01:51 PM
Callback when using form_validation.php $config array - by El Forum - 07-14-2009, 01:56 PM
Callback when using form_validation.php $config array - by El Forum - 07-14-2009, 01:56 PM
Callback when using form_validation.php $config array - by El Forum - 07-14-2009, 02:13 PM
Callback when using form_validation.php $config array - by El Forum - 07-14-2009, 02:22 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.