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

Error messages in SmartyValidate

 
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
foof
Smarty n00b


Joined: 21 Dec 2004
Posts: 1

PostPosted: Tue Dec 21, 2004 10:15 am    Post subject: Error messages in SmartyValidate Reply with quote

I want my errormessages to be listed under each other, it seems like I can't do this with <br /> in the message:

{validate field="name" criteria="notEmpty" message="Missing name<br />"}
{validate field="email" criteria="notEmpty" message="Missing email<br />"}

How can I do this if I don't want the <br /> to show if there is no errormessages?
Also, I want the text in the color red, how do I do this the easiest way?
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Tue Dec 21, 2004 2:37 pm    Post subject: Reply with quote

Something like this:

{validate field="name" criteria="notEmpty" message="Missing name" append="errors"}
{validate field="email" criteria="notEmpty" message="Missing email" append="errors"}

Then loop over $errors array and display them however you wish.
Back to top
View user's profile Send private message Visit poster's website
gestionti
Smarty Rookie


Joined: 02 Mar 2005
Posts: 15
Location: Gatineau, Qc, Canada

PostPosted: Wed Mar 02, 2005 11:19 pm    Post subject: Reply with quote

I am learning Smarty and I like it so far... Been trying SmartyValidate and I want to display the error messages at the bottom of the form. Error messages will not appear. Here is what I have:

<form method="post" action="validate.php">
{validate field="FullName"
criteria="notEmpty"
transform="trim"
message="Full Name Cannot Be Empty" append="errors"}
Full Name: <input type="text"
name="FullName" value="{$FullName|escape}"><br />
{validate field="Phone"
criteria="isNumber"
empty="yes" transform="trim"
message="Phone Number Must be a Number" append="errors"}
Phone :<input type="text"
name="Phone" value="{$Phone|escape}" empty="yes"><br />
etc.... and finally :

{if !empty($errors)}
<table border="1">
<TR><TD COLSPAN="3"><FONT COLOR=#ff0000>
{section name=msg loop=$errors}
error: {$errors[msg]}<br>
{/section}
</FONT></TD></TR></table>
{/if}
All I get listed is error:

please advise.
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Thu Mar 03, 2005 6:58 am    Post subject: Reply with quote

does {$errors|@print_r} show anything?
Back to top
View user's profile Send private message Visit poster's website
gestionti
Smarty Rookie


Joined: 02 Mar 2005
Posts: 15
Location: Gatineau, Qc, Canada

PostPosted: Thu Mar 03, 2005 1:16 pm    Post subject: Reply with quote

Thanks for reply! Smile

I place the {$errors|@print_r} within the section tag, and here is the output.

error: E
Array ( [FullName] => Enter full name [Phone] => Phone Number Must be a Number [CCExpDate] => Exp Date not valid ) 1
error: x
Array ( [FullName] => Enter full name [Phone] => Phone Number Must be a Number [CCExpDate] => Exp Date not valid ) 1
error: p
Array ( [FullName] => Enter full name [Phone] => Phone Number Must be a Number [CCExpDate] => Exp Date not valid ) 1

In the means time, I tried with {foreach} tag like so :

{if !empty($errors)}
<table border="1">
<TR><TD COLSPAN="3"><FONT COLOR=#ff0000>
{foreach from=$errors item=error}
erreur: {$error}<br>
<br>
{/foreach}
</FONT></TD></TR></table>
{/if}

And so far this seems to be working...
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Thu Mar 03, 2005 2:38 pm    Post subject: Reply with quote

SmartyValidate is appending $key => $val to the array each time, with $key being the name of the field with the error. Using a {section} loop won't work because it requires zero-index keys. Foreach will work fine, as you are doing.
Back to top
View user's profile Send private message Visit poster's website
gestionti
Smarty Rookie


Joined: 02 Mar 2005
Posts: 15
Location: Gatineau, Qc, Canada

PostPosted: Thu Mar 03, 2005 10:36 pm    Post subject: Reply with quote

Outstanding!!

Now my other problem is with Radio button. User must select male of female. Not sure how I validate this. It cannot be empty. I tried this and it does not work :

{validate field="sexe"
criteria="notEmpty"
message="Sélectionner un genre"
append="errors"}
<input type="radio" name="sexe" value="{$homme|escape}" tabindex="4">Homme<br />
<input type="radio" name="sexe" value="{$femme|escape}" tabindex="5">Femme<br />

Plus if I make a selection, when it returns to the form after validation, nothing is selected.
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Thu Mar 03, 2005 10:50 pm    Post subject: Reply with quote

You submit the form with nothing selected and it doesn't come up with an empty error message? Or something else?

As for not being selected on redraw, that is because you need to identify which one is selected (or more properly "checked" with radios);

<input type=radio name=sexe value=foo {if $sexe eq "foo"}checked="checked"{/if}>

Look at the {html_radios} function that comes with Smarty, it will ease the pain with managing radio button generation/selection. Same with {html_options} and {html_checkboxes}
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: Thu Mar 03, 2005 10:52 pm    Post subject: Reply with quote

btw, any time you change validation criteria in the template during development, clear the validation session data!
Back to top
View user's profile Send private message Visit poster's website
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