Welcome Guest, Not a member yet? Register   Sign In
Form Validation To Check Min and Max values in two fields
#2

[eluser]TheFuzzy0ne[/eluser]
Your rules:
Code:
$this->form_validation->set_rules('cost-min', 'Cost Min', 'required|numeric'); // should always be lower than cost-max
$this->form_validation->set_rules('cost-max',  'Cost Max', 'required|numeric|callback__more_than[cost-min]'); // should always be higher

In your controller, add the following method.
Code:
function _more_than($str, $field='')
{
    // Don't run bother checking if we have a form error on cost-min.
    if  (form_error('cost-min')) {
        return true;
    }

    $str = intval($str);
    $min = intval($this->input->post($field));
    
    if ($str <= $min) {
        $this->form_validation->set_message('_more_than', "The %s field must be more than {$min}.");
        return false;
    }
    
    return true;
}

I've not tested it, but it should give you something to go on.

Hope this helps.


Messages In This Thread
Form Validation To Check Min and Max values in two fields - by El Forum - 03-23-2013, 08:21 AM



Theme © iAndrew 2016 - Forum software by © MyBB