Welcome Guest, Not a member yet? Register   Sign In
Wrong value passed as parameter for a callback function
#1

[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?
#2

[eluser]CroNiX[/eluser]
Whatever is passed in as the 2nd parameter is a string. It would be pretty limiting to force you to only be able to use the name of an input there.

In your case, you'd simply have to do something like:
Code:
$old = $this->Support_model->decimal_format($this->input->post($old, TRUE));
#3

[eluser]Alhazred[/eluser]
Thanks, that works. Smile




Theme © iAndrew 2016 - Forum software by © MyBB