Welcome Guest, Not a member yet? Register   Sign In
Function set_value() not working as expected
#41

[eluser]FireStarter[/eluser]
According to this issue on GitHub, the problem is a 'known limitation'.

https://github.com/EllisLab/CodeIgniter/issues/1348

The problem is, what happens if you have the validation library auto loaded?

20,000 views suggest that this is a real problem. The documents don't describe this 'limitation' at all. We should really have this bug fixed, or if it's not considered a bug, just have the feature updated.

For example, I autoload the validation library but on my login form (email/password only), I don't wish to run any validation - it's pointless, for me. I do however wish to stick with set_value() to keep the email address in place when the password is wrong.

Does anybody else feel that the functionality should be changed?

Edit:

Looks like the issue may have actually been fixed in CodeIgniter 3.0. Can anyone who is more familiar with GitHub (I'm not a user myself) confirm this? I'm looking at: https://github.com/EllisLab/CodeIgniter/pull/1581

Thanks

Edit 2:

My bad. That pull request is just an update to the documentation. Lame.

So if I autoload the validation class I MUST validate EVERY INPUT or else set_value becomes useless. How ridiculous.
#42

[eluser]Aken[/eluser]
We all agree that it's a pain to define empty validation rule sets for fields, yes. A solution will come much quicker if the community contributes a solution. The Reactor devs - who are also parts of the community, not EllisLab staff - have enough on their plate most of the time.
#43

[eluser]FireStarter[/eluser]
Ah right, fair do's. Just a bit strange that this hasn't been really addressed in so many years. Seems like a gaping big hole which must annoy a fair few people!

I don't know much about the inner workings of CodeIgniter but I'll see if I can have a look at the code soon and come up with something. No doubt it isn't quite as easy as it sounds, considering nobody has put something forward so far Wink It's worth me having a bash though!
#44

[eluser]Aken[/eluser]
It shouldn't be difficult to do. But people are either busy, or assume that someone else will do it.

set_value() works fine if you do not load the Validation library. But if you DO load it, then it checks if the corresponding field has a rule set defined. If YES, then it works fine. If NO, it fails quietly and doesn't do anything. Shouldn't be hard to add a check to see if the field is defined on top of if the library is loaded.
#45

[eluser]Unknown[/eluser]
So, the problem is how set_value works when validation is also being used (as many have pointed out).

From the validation rules section in the documentation ...

"Note: You can also use (as a rule) any native PHP functions that permit one parameter."

So, for any form variables not needing validation, use something that will always be true, like isset and set_value will return the $_POST variable, as desired

$this->form_validation->set_rules('field', '', 'isset')

It's extra code in the controller, but this will allow set_value() to behave as expected when you are using validation ... and it will probably keep working through an upgrade if they don't get around to fixing.

It could be easier, no doubt (and I suspect others have posted the same/similar work-around).




Theme © iAndrew 2016 - Forum software by © MyBB