• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
numeric form validation does not work

#1
[eluser]Cgull[/eluser]
Hello,

I have a form with an input field:
Code:
$espresso = array('name'=>'espresso', 'size'=>'1', 'maxlength'=>'3', 'value'=>set_value('espresso'));

In my controller I have this validation rule:

Code:
$this->form_validation->set_rules('espresso', 'Qty', 'trim|numeric');

I put a letter in the espresso field, submit the form and I don't get any error.

If I try this rule:

Code:
$this->form_validation->set_rules('espresso', 'Qty', 'trim|required');

I get a nice beatiful error that the field is required.

Why don't I get the error for the numeric rule?

Thanks

#2
[eluser]phpfresher[/eluser]
I also having the similar problem in password and confirm password field . But i solve it in a different way.
User the callback function .
Code:
$this->form_validation->set_rules('espresso', 'Qty', 'trim|numeric');
to

Code:
$this->form_validation->set_rules('espresso', 'Qty', 'trim|callback_numeric_check');  

function numeric_check($num){
if(!isset($num)){
   return false;
}
perform the numeric check .. or paste the code from form_validation library into it.
}

But it is not the actual solution but its the last solution. Actually numeric would work. But in case if you cant solve the problem follow the above approach.

#3
[eluser]Cgull[/eluser]
Thank you, I will try your way until we get another solution.

Will post here if I find something.

#4
[eluser]boltsabre[/eluser]
Hmmm, at a casual glance it should work. Have you tried either of these rules instead:
integer
is_natural
is_natural_no_zero

#5
[eluser]Cgull[/eluser]
Hi Boltsabre,

I tried integer as well, did not work.

#6
[eluser]Cgull[/eluser]
It suddenly started working, don't know how and why.

#7
[eluser]boltsabre[/eluser]
That is really strange... You weren't defining two sets of validation rulesets, overriding the first one by any chance???

Code:
$this->form_validation->set_rules('espresso', 'Qty', 'trim|numeric');
...
...
$this->form_validation->set_rules('espresso', 'Qty', 'trim');
And in fact, I'm not even sure if this would override the first set, never tested it, just a thought...
Another thought... make sure your virus scan is fully up to date and run a full scan of all your devices...

#8
[eluser]Aken[/eluser]
Yeah, I can't see any reason why numeric would pass with a letter in it (at least the current version of the form validation lib). Might've had something to do with your code elsewhere.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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