Welcome Guest, Not a member yet? Register   Sign In
Trying to apply a function to form validation set_value [SOLVED, with thanks!]
#21

[eluser]Dennis Rasmussen[/eluser]
Quote:Actually, this must be a common thing if you want to strip tags and newlines and show the raw text back to the user.
What you're doing isn't common in anyway to us.
If you don't need validation (with error messages) on newlines and returns then don't use validation for that.

Simply strip the text for the view if there's an error with the OTHER rules and then strip the text when inserted into the database (even though it's a better practice to keep the raw data in there and strip it in the output instead).

You are making it harder for yourself... when it's really not needed.
#22

[eluser]nuwanda[/eluser]
No, not if you want to show the user how their text will be eventually be shown.

DZone has the correct approach, I think.

Besides, one statement to rip out the newlines is no big deal.

I'm happy :-)
#23

[eluser]Dennis Rasmussen[/eluser]
*facepalm*

Quote:No, not if you want to show the user how their text will be eventually be shown.

"Simply strip the text for the view"
#24

[eluser]nuwanda[/eluser]
But that was the original problem!

The validation class shows the input values with set_value.

The only way to show the stripped input for the user was to process it before the validation so that set_value could repopulate the textarea with the stripped text.

Again, using a native function in the validation rule (like trim) works just fine, but the only solution in this case was to process it prior to the validation. Try it.
#25

[eluser]Dennis Rasmussen[/eluser]
native_function(set_value('field', '')) ?




Theme © iAndrew 2016 - Forum software by © MyBB