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

SmartyValidate 2.7 released
Goto page Previous  1, 2, 3, 4  Next
 
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
brice
Smarty Rookie


Joined: 14 Apr 2006
Posts: 11

PostPosted: Sun Apr 16, 2006 8:40 am    Post subject: translation of error messages Reply with quote

I'm using gettext,php gettext, and smarty-gettext to handle i18n of a project...

I've just switched over to Smarty and am learning the ropes. I really like this class & plan on using it (+ perhaps one day popping the hood to add drop in client side JS validation).

Anway, I came across one hitch; Translating the text of an error message. Translation occurs (calls gettext function(s) on text between the {t}{/t} block.

Here's an example:
<div class="error">{validate id="email" message="{t}Invalid email address{/t}"}</div>

Results in:

Fatal error: Smarty error: [in user/login.tpl line 21]: syntax error: mismatched tag {/t}. (Smarty_Compiler.class.php, line 2286) ..

Can anyone suggest a workaround? Smile
Back to top
View user's profile Send private message
kills
Smarty Elite


Joined: 28 May 2004
Posts: 493

PostPosted: Sun Apr 16, 2006 3:52 pm    Post subject: Reply with quote

its not allowed to nest smarty tags

you have to save it in a temp var
Back to top
View user's profile Send private message
brice
Smarty Rookie


Joined: 14 Apr 2006
Posts: 11

PostPosted: Sun Apr 16, 2006 6:28 pm    Post subject: Reply with quote

can I assign temp vars in the template file (so the error message remains in designer view)? it's too bad because there's no way to around this w/o adding much clutter Sad

~ Brice
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 16, 2006 8:03 pm    Post subject: Reply with quote

maybe something like this:

Code:
{validate id="email" message="Invalid email address" assign="error"}
{t}{$error}{/t}
Back to top
View user's profile Send private message Visit poster's website
brice
Smarty Rookie


Joined: 14 Apr 2006
Posts: 11

PostPosted: Sun Apr 16, 2006 9:28 pm    Post subject: Reply with quote

Monte,

That solution is certainly the most elegant... however, I believe the translators would see "{$error}" as the text to translate rather than "Invalid email address" due to the way gettext / smartygettext pulls strings to be translated from files?

I've opted to assign the error message from the PHP parent script, and if a user want's to customize the error message, they can easily do it in their own language w/o the need for the translation function.

Here's my code (which I have no idea of its quality...)

Parent PHP: _T() is the translation function
Code:
if (empty ($_POST)) {
   //____ FORM NOT SUBMITTED ____
   $formError = array();
   SmartyValidate :: connect($smarty, true);
   SmartyValidate :: register_validator('email', 'Email', 'isEmail', false, false, 'trim');
   $formError['email'] = _T('Invalid email address');
   $smarty->assign('formError',$formError);
   $smarty->display('user/login.tpl');
} else {


Template:
Code:

<form action="" method="POST">
   <fieldset>
      <legend>{t}Login{/t}</legend>
   
      <div class="field">
         <div class="error">{validate id="email" message=$formError.email}</div>
         <label for="Email"><span class="required">{t}Your Email:{/t} </span></label>
         <input type="text" class="text" size="32" maxlength="60"
           name="Email" value="{$Email|escape}" id="email" />
           <input style="margin-left: 30px;" type="submit" value="{t}Login{/t}" />
      </div>
      
   </fieldset>
   </form>


PS -> Thanks for your dedication!! Smile
Back to top
View user's profile Send private message
brice
Smarty Rookie


Joined: 14 Apr 2006
Posts: 11

PostPosted: Tue Apr 18, 2006 2:02 am    Post subject: documentation type Reply with quote

typo @ documentation:

line 827 -> SmartyValidate::register_validator('v_username','username:!^\w+$!','isLength');

should read
SmartyValidate::register_validator('v_username','username:!^\w+$!','isRegExp');

? Smile
Back to top
View user's profile Send private message
brice
Smarty Rookie


Joined: 14 Apr 2006
Posts: 11

PostPosted: Thu May 04, 2006 11:23 pm    Post subject: Cannot have an option isEqual field? Reply with quote

I've struggled to have an optional isEqual field. For instance;

I have a form listing a user's information, along with two password fields. If the user types the same password in both fields, the password will be changed upon a valid form submittal. If the fields are left blank, the password will not be changed.

The form never registers as valid if the passwords are left blank -- even though a dump of the SmartyValidate object shows that the field passed validation!

Here's the validator's I've tried;

Code:

1)
   SmartyValidate :: register_validator('admin_password2', 'admin_password2:admin_password', 'isEqual',TRUE);

2)
SmartyValidate :: register_validator('admin_password', 'admin_password:admin_password2', 'isEqual',TRUE);
   SmartyValidate :: register_validator('admin_password2', 'admin_password2:admin_password', 'isEqual',TRUE);

3)
SmartyValidate :: register_validator('admin_password', 'admin_password', 'dummyValid');
   SmartyValidate :: register_validator('admin_password2', 'admin_password2:admin_password', 'isEqual',TRUE);


form fields are text input.

Will I have to find a workaround? Smile
Back to top
View user's profile Send private message
OpenMacNews
Smarty Rookie


Joined: 03 Aug 2004
Posts: 34
Location: Floating on Io's Methane Seas ...

PostPosted: Thu May 11, 2006 6:27 am    Post subject: SmartyValidate & ZF? Reply with quote

hi all.

as i keep pluggin along with Zend Framework, next step is validation.

i understand that there *is* a Zend_Validate class 'proposal' somewhere out ther (not holding my breath ...), and SmartyValidate is *here* & working great now.

that said, has anyone thought about the integration of SmartyValidate + ZF?

the two obvious approaches include either ignoring the ZF as much as possible, and simply using SmartyValidate within the smarty tpl context, and/or extending a Zend class for tighter integration.

Currently, i've taken the extend Zend_View class for integrating Smarty templating; working fine so far. so, my first inclination is to do the same with Validate ... altho, it's kinad moot until it actually exists!

nonetheless, i'd be interested in folks' thoughts on ZF + validate ...

cheers,

richard
Back to top
View user's profile Send private message
kills
Smarty Elite


Joined: 28 May 2004
Posts: 493

PostPosted: Mon Jun 26, 2006 8:41 am    Post subject: Reply with quote

Hi monte,

is it the intended behavior that isValid returns false if no validator is registered?

Bye,
Markus
Back to top
View user's profile Send private message
kills
Smarty Elite


Joined: 28 May 2004
Posts: 493

PostPosted: Fri Jun 30, 2006 6:53 am    Post subject: Reply with quote

anyone?
Back to top
View user's profile Send private message
boots
Administrator


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

PostPosted: Fri Jun 30, 2006 7:22 pm    Post subject: Reply with quote

@kills: I wouldn't think that was intended but it is an interesting corner case. If there are no validators registered, why is SmartyValidate being loaded/used at all?
Back to top
View user's profile Send private message
kills
Smarty Elite


Joined: 28 May 2004
Posts: 493

PostPosted: Wed Jul 05, 2006 10:11 am    Post subject: Reply with quote

Hi boots,

Maybe you are right.

I`m using SmartyValidate in an non-smarty env with a full-automated validation system and so I am not sure if I have to handle this problem with my framework, or is it only a bug in SmartyValidate itself...

It would be a complex task to if-case this situation through the whole framework and thats the reason why I post here in the forums.

Maybe its a bug, but if not, I will fix it in the framework..

Thanks,
Markus
Back to top
View user's profile Send private message
boots
Administrator


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

PostPosted: Wed Jul 05, 2006 3:11 pm    Post subject: Reply with quote

Hi Kills.

Although I think it is rare case, I do agree that it is probably a case that should be handled. I would fix it myself, but I haven't looked at the code in quite a while. Maybe Monte is following this thread ... if not, send me a patch and I will try to remember my cvs password Smile
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 05, 2006 4:43 pm    Post subject: Reply with quote

kills wrote:
Hi monte,

is it the intended behavior that isValid returns false if no validator is registered?

Bye,
Markus


More likely an oversight. If you don't register a validator, then why load the class at all?
Back to top
View user's profile Send private message Visit poster's website
kills
Smarty Elite


Joined: 28 May 2004
Posts: 493

PostPosted: Fri Jul 07, 2006 3:26 pm    Post subject: Reply with quote

Hi,

i subclassed the SmartyValidate Class und handeled it this way

Bye,
Markus
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
Goto page Previous  1, 2, 3, 4  Next
Page 2 of 4

 
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