CodeIgniter icon indicating copy to clipboard operation
CodeIgniter copied to clipboard

Form_validation invalid checking

Open aanbar opened this issue 14 years ago • 4 comments

Form_validation Currently checking posted variables only.

Example: view.php <input type="text" name="txt" />

if I set the validation rules for this field in the controller Something.php function index() { $this->form_validation->set_rules('txt', 'Text', 'trim|required'); if ( $this->form_validation->run() == false ) { echo validation_errors(); }else{ echo "form has passed checks"; } }

if I call my script http://127.0.0.1/something , I should be getting errors from validation ... but that's not the case as it is checking if variables are posted or not then it will return false without any errors so I end up with empty page.

It should be noted though this makes some of the tests useless like (required, isset).

My thought: form_validation should be checking based on rules not the posted variables.

aanbar avatar Mar 05 '12 15:03 aanbar

This is a totally different issue. But looking at the latest form_validation library in Github, looks like this has been resolved (I will have to test it out though).

aanbar avatar Mar 05 '12 22:03 aanbar

@aanbar Did you get the chance to test that?

narfbg avatar Mar 07 '12 21:03 narfbg

Sorry for being late, but I had a busy schedule.

I have just tested the latest uploaded file here & it has the same issue.

I have modified the old version of form_validation to fix this error & I am using it in my apps now. I don't have Git tools in my computer therefore I am unable to submit it.

Basically I have disabled everything related to checking if something was posted or not which means if you requested something through "GET" instead of "POST" you'll get the validation_errors.

aanbar avatar Mar 08 '12 14:03 aanbar

OK, I can't understand exactly what you mean with the issue description, but here's the two possibilities I'm thinking of:

  1. You mean that checks shouldn't halt if there's no data actually to process, but it must try to validate data if it's a POST request.
  2. You mean that if there's a form to be displayed on the page - validation must be executed no matter what.

If it's the first case, then this recent commit should fix the issue: https://github.com/EllisLab/CodeIgniter/commit/3b2c5083034675d88d9e516b5c5aca5119d6f918. It is from around 20 hours ago, so you probably haven't tried with it yet.

If it's the second case however - it's not a bug, it's a feature. ;) That's what I understood the first time I read your issue's description, but I assumed it's not that because ... well, I don't want to sound rude, but - that's nonsense. If that was to be done, every single login form (just an example) would trigger a "Wrong username and/or password" to be displayed when a user goes to the login screen of a website.

narfbg avatar Mar 08 '12 17:03 narfbg