Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

validate multiple fields

 
Post new topic   Reply to topic    Smarty Forum Index -> Add-ons
View previous topic :: View next topic  
Author Message
Dieter
Smarty Rookie


Joined: 08 Sep 2003
Posts: 9

PostPosted: Thu Jul 29, 2004 2:23 pm    Post subject: validate multiple fields Reply with quote

I'm trying to build some forms for my website and I'm using SmartyValidate but I've come across some problems:

I have a few fields that should be INTs, but at least 1 of these fields should be > 0.
Code:

{validate field="f1" criteria="isInt" transform="trim" message="##NG_OK##"}
  <li><input type="text" name="f1" value="{$f1}"><br />
{validate field="f2" criteria="isInt" transform="trim" message="##NG_OK##"}
  <li><input type="text" name="f2" value="{$f2}"><br />
{validate field="f3" criteria="isInt" transform="trim" message="##NG_OK##"}
  <li><input type="text" name="f3" value="{$f3}"><br />


I should have a general {validate field="f1 OR f2 OR f2 criteria="not0"} on top of this but I don't think this is possible?

I hope that someone can help me out.
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Thu Jul 29, 2004 2:36 pm    Post subject: Reply with quote

There isn't an easy way to do this yet. You could create a custom criteria for it:

{validate field="f1,f2,f3" critieria="oneIsGtZero" message="..."}
Back to top
View user's profile Send private message Visit poster's website
Dieter
Smarty Rookie


Joined: 08 Sep 2003
Posts: 9

PostPosted: Thu Jul 29, 2004 2:51 pm    Post subject: Reply with quote

mohrt wrote:
There isn't an easy way to do this yet. You could create a custom criteria for it:

{validate field="f1,f2,f3" critieria="oneIsGtZero" message="..."}


I figured that out, but how can you validate multiple fields with one {validate} -tag? Separating them with ", " doesn't seem to work...
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Thu Jul 29, 2004 2:56 pm    Post subject: Reply with quote

Your validation logic would need to split the values by commas and test each them. None of the criteria bundled with SmartyValidate work this way.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    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