Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Clearing the form input field when an error occured?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Add-ons
View previous topic :: View next topic  
Author Message
pabianjs
Smarty Rookie


Joined: 28 Jun 2004
Posts: 6

PostPosted: Wed Jul 14, 2004 9:04 pm    Post subject: Clearing the form input field when an error occured? Reply with quote

hi guys,

as of now, it doesn't appear that the validator clears the input field, if that input fails the validation.

is it out of the question to get it to do so? the wiped input field would just be another visual que to the user that something went wrong.. god knows they barely read the error messages to begin with.

as to the implementation could another function attribute be added. something like below

{validate form=PG3 field="lname" clear="yes" .......}

this is just an idea..

thanks

jeff
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed Jul 14, 2004 9:56 pm    Post subject: Reply with quote

That does sound useful, although it is not as straight forward as it sounds. Wink

First off, clearing the form field may not always be the desired behavior, what if you are validating a set of radio buttons and to "clear" them means to select the first one? I would think of it more like a "reset" rather than a "clear". This could be accomplished with a reset parameter:

{validate field="name" criteria="isLength" max=10 reset="" message="..."}

Now, the validator can only reset values in the array passed to is_valid(), so it would be up to you to assign this array to the template and use the correct values on the form (SmartyValidator can't distinguish what template var names you are using on the form!)

This *should* work for fields generated by {html_date} too, so long as you keep the hidden field name the same as what is passed to the "time" parameter of {html_date} and reset that value to a date (or empty for current date.)

This is a good idea though, it abstracts one more element of form validation from the PHP code to the validator tag, and rightfully goes there since this can be considered part of the validation and easily adjusted from there.

Thats all I can think of without actually trying to implement this. Wink
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed Jul 14, 2004 10:02 pm    Post subject: Reply with quote

One other issue is resetting to an array of values, in the case of a checkbox list. Maybe a comma-separated list as the reset parameter would suffice (?) (or a preset template var as an array)
Back to top
View user's profile Send private message Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Jul 14, 2004 10:04 pm    Post subject: Reply with quote

Sigh. I personally don't favour this idea. Validation is not the same thing as display which is not the same thing as process. The template designer has everything at their disposal to be able to decide if the value should be cleared or retained. This also continues the trend to put data related processing into the hands of the designer instead of the application. Aren't templates supposed to render data as supplied to them?

If you come up with a new plugin-type (field?) that combines process semantics with validation semantics and display semantics, that is one thing. Overloading everything into the validator is quite another, at least from my stand-point.

Then again, for small projects where the application isn't already doing validation, this is just one more handy tool. Still, it looks a lot like rope to me.

Just my crumudgenly 2c
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed Jul 14, 2004 10:26 pm    Post subject: Reply with quote

I don't disagree with you boots... When I first began to toy with the idea of putting validation criteria functions into the template it meant stepping into the process/presentation boundary. But after deploying this across a couple applications, it worked out way better than expected. Putting the form validation criteria right along side the form made things so much easier from several angles... the PHP processing code was abstracted down to a few register_form() and is_valid() calls, and the criteria can easily be located (just find the form), and adjusted with minimum effort.

I haven't made up my mind on this one yet, I'm pretty much considering SmartyValidate a concept test and see what issues it creates or solves. So far it hasn't caused any problems (outside of the designer having access to form validation criteria, which in my case they pretty much ignore the validation tags.)
Back to top
View user's profile Send private message Visit poster's website
pabianjs
Smarty Rookie


Joined: 28 Jun 2004
Posts: 6

PostPosted: Thu Jul 15, 2004 1:48 pm    Post subject: Reply with quote

first both of you brought up good points. after my post i went back and looked at the validator class and recognized it probabally wouldnt be as easy as i thought.. mohrt you are right about the other input tags and how to handle them. it looks to be messy.. and this was just a thought..

the validator the way it is now is going to make my job easier.. no question about it.

thanks guys
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Add-ons All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP