View previous topic :: View next topic |
Author |
Message |
Net Genius Smarty Rookie
Joined: 25 Aug 2008 Posts: 7
|
Posted: Mon Aug 25, 2008 4:02 pm Post subject: [SV] assign="..." not working |
|
|
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. it's empty.
Can anyone offer any suggestions? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Aug 25, 2008 4:03 pm Post subject: |
|
|
Can you verify the error happens? First see if you can get the error to display in place. |
|
Back to top |
|
Net Genius Smarty Rookie
Joined: 25 Aug 2008 Posts: 7
|
Posted: Mon Aug 25, 2008 4:07 pm Post subject: |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Aug 25, 2008 4:59 pm Post subject: |
|
|
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 |
|
Net Genius Smarty Rookie
Joined: 25 Aug 2008 Posts: 7
|
Posted: Mon Aug 25, 2008 8:02 pm Post subject: |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Aug 25, 2008 10:41 pm Post subject: |
|
|
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:
Will definitely wipe it all out. |
|
Back to top |
|
cegottardi Smarty n00b
Joined: 11 Apr 2009 Posts: 1
|
Posted: Sat Apr 11, 2009 1:39 am Post subject: |
|
|
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 |
|
|