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

[SV] assign="..." not working

 
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
Net Genius
Smarty Rookie


Joined: 25 Aug 2008
Posts: 7

PostPosted: Mon Aug 25, 2008 4:02 pm    Post subject: [SV] assign="..." not working Reply with quote

Hi. I'm having some trouble getting the assign feature of smartyValidate working.

I've created my error message
Code:
{validate id="furl" message="Please input a url." assign="error_url"}
but when I try and access the variable, i.e.
Code:
{$error_url}
it's empty.

Can anyone offer any suggestions?
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Mon Aug 25, 2008 4:03 pm    Post subject: Reply with quote

Can you verify the error happens? First see if you can get the error to display in place.
Back to top
View user's profile Send private message Visit poster's website
Net Genius
Smarty Rookie


Joined: 25 Aug 2008
Posts: 7

PostPosted: Mon Aug 25, 2008 4:07 pm    Post subject: Reply with quote

When I use
Code:
{validate id="furl" message="Please input a url."}
the error shows up as expected. However, as I'm sure you realise, I want the value of the error to be assigned to the variable.
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Mon Aug 25, 2008 4:59 pm    Post subject: Reply with quote

Make sure you clear out your session (reset validation) when you add the assign parameter in so the session gets this info.
Back to top
View user's profile Send private message Visit poster's website
Net Genius
Smarty Rookie


Joined: 25 Aug 2008
Posts: 7

PostPosted: Mon Aug 25, 2008 8:02 pm    Post subject: Reply with quote

I'm not sure what you mean, can you give me an example?

This is my code

Code:
   if(empty($_POST)) {
      SmartyValidate::connect($smarty, true);
      SmartyValidate::register_validator('fname','name','notEmpty');
      SmartyValidate::register_validator('furl','url','isURL', true);
      SmartyValidate::register_validator('fownerID','ownerID','isInt');
      $smarty->display('admin.tpl');
   } else {
      SmartyValidate::connect($smarty);
      // validate after a POST
      if(SmartyValidate::is_valid($_POST)) {
         // no errors, done with SmartyValidate
         SmartyValidate::disconnect();
         $smarty->display('success.tpl');
      } else {
         // error, redraw the form
         $smarty->assign($_POST);
         $smarty->display('admin.tpl');
      }
   }


Code:
   <form method="post" action="admin.php">
   <fieldset><legend>Add Company</legend>
   
   <p><label for="name" class="left">Name:</label>
   <input type="text" name="name" id="name" class="field" value="{$name|escape}" tabindex="1" maxlength="25" />
   {validate id="fname" message="Please input a name."}</p>
   
   <p><label for="description" class="left">Description:</label>
   <textarea name="description" id="description" cols="45" rows="4" tabindex="2" maxlength="255">{$description|escape}</textarea></p>
   
   <p><label for="address" class="left">Address:</label>
   <textarea name="address" id="address" cols="45" rows="4" tabindex="3" maxlength="255">{$address|escape}</textarea></p>
   
   <p><label for="postcode" class="left">Post code:</label>
   <input type="text" name="postcode" id="postcode" class="field" value="{$postcode|escape}" tabindex="4" maxlength="10" /></p>
   
   <p><label for="telephone" class="left">Telephone:</label>
   <input type="text" name="telephone" id="telephone" class="field" value="{$telephone|escape}" tabindex="5" maxlength="15" /></p>
   
   <p><label for="url" class="left">URL:</label>{$error_url}
   <input type="text" name="url" id="url" class="field" value="{$url|escape}" tabindex="6" maxlength="50" />
   {validate id="furl" message="Please input a url." assign="error_url"}</p>
   
   <p><label for="ownerID" class="left">Owner <a href="http://www.worcestersource.net/forum/index.php?act=Members" target="_blank">ID</a>:</label>
   <input type="text" name="ownerID" id="ownerID" class="field" value="{$ownerID|escape}" tabindex="7" maxlength="5" />
   {validate id="fownerID" message="Please input an integer."}</p>
   
   <p><input type="submit" name="submit" id="submit" class="button" value="Send message" tabindex="99" /></p>
   
   </fieldset>
   </form>
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Mon Aug 25, 2008 10:41 pm    Post subject: Reply with quote

Just reset the sessions once if you add/remove that parameter, to be sure the changes take place.

Code:
SmartyValidate::connect($smarty, true);


That would do it, or:

Code:
unset($_SESSION);


Will definitely wipe it all out.
Back to top
View user's profile Send private message Visit poster's website
cegottardi
Smarty n00b


Joined: 11 Apr 2009
Posts: 1

PostPosted: Sat Apr 11, 2009 1:39 am    Post subject: Reply with quote

Code:
<p><label for="url" class="left">URL:</label>{$error_url}
   <input type="text" name="url" id="url" class="field" value="{$url|escape}" tabindex="6" maxlength="50" />
   {validate id="furl" message="Please input a url." assign="error_url"}</p>


I think that the problem is that the {$error_url} variable is before the validate syntax.
Just write it after and you will see the message.

Sorry for my english.
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