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

question about multiple error messages on a form

 
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
mongo
Smarty Rookie


Joined: 23 Apr 2005
Posts: 8

PostPosted: Sat Apr 23, 2005 10:52 pm    Post subject: question about multiple error messages on a form Reply with quote

Hi I am new to Smarty and SmartyValidate. I need to set up the validation for my form in a particular way and I have been looking all over the board for suggestions of how to do it. So far I haven't found what I am looking for; so i figured I might as well just ask.

I want to have a form template where the error message is displayed next to the field. I need multiple error messages (and thus multiple register_validators)for some fields but only one error message may be displayed at a time when the "submit" button is pressed. Thus if the first validator passes and the second one doesn't, only the error message for the second validator will be displayed (at the exact same place on the form where the first one would have been displayed).

What I want to know is: is there a way to do this that is native to SmartyValidate or does it need some sort of creative workaround?
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Sun Apr 24, 2005 1:42 pm    Post subject: Reply with quote

each validator has a "halt" parameter, set that to true and validation will halt when on fails.
Back to top
View user's profile Send private message Visit poster's website
mongo
Smarty Rookie


Joined: 23 Apr 2005
Posts: 8

PostPosted: Sun Apr 24, 2005 7:36 pm    Post subject: Reply with quote

Just setting the "halt" parameter won't insert the appropriate error msg into a designated place on the form will it?

It occured to me after looking at other postings that maybe what I need to do is something like this:

form.tpl

{validate id = "f_nameempty" ... assign="f_nameerr" message="First Name field is empty"}
{validate id = "f_nameletters" ... assign="f_nameerr" message="First Name field must have letters only" }
{validate id = "l_nameempty" ... assign="l_nameerr" message="Last Name field is empty"}

etc.

//put all validates at top of the form template and assign errors to variables. Then further down, the form itself...

<input type="text" name="firstname" value="{$FName|escape}">{$f_nameerr}<br />

<input type="text" name="lastname" value="{$LName|escape}">{$l_nameerr}<br />

//variable containing the appropriate error msg is situated next to the proper field on the form

Will this work? More importantly, if everything validates and no error msgs are inserted into the variables, will the space on the form where the error messages are placed be blank or would I have to do something else?
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Sun Apr 24, 2005 7:40 pm    Post subject: Reply with quote

that should work, and the vars will be empty if there are no errors
Back to top
View user's profile Send private message Visit poster's website
mongo
Smarty Rookie


Joined: 23 Apr 2005
Posts: 8

PostPosted: Sun Apr 24, 2005 7:50 pm    Post subject: Reply with quote

Thank you for your help.
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