[eluser]Alhazred[/eluser]
I have to validate a form, among the fields there are:
Code:
<input type='text' name='price' />
<input type='hidden' name='old_price' value='45.99' />
Inside the controller I have
Code:
$this->form_validation->set_rules('price','lang:crd_form_price','trim|required|xss_clean|valid_price'); //valid_price is a function which I added in the Form_validation.php and it works
$this->form_validation->set_rules('old_price','lang:crd_form_old_price','trim|callback_match_price[price]');
I don't use the native matches because the prices could be inserted in different formats, so I can't just make a simple ==, I need to manipulate them before to compare.
The callback is
Code:
function match_price($new,$old)
{
$new = $this->Support_model->decimal_format($new);
$old = $this->Support_model->decimal_format($old);
if ( $new != $old )
{
$this->form_validation->set_message('match_price',lang('crd_form_pricediff'));
return FALSE;
}
else
{
return TRUE;
}
}
This always returns false, so I've put inside the function this line at the beginning
echo $new.' - '.$old; exit;
It prints: 45.99 - price
For the 2nd parameter it receives the name of the field, not the value, what's the problem?