|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
Smartyeater Smarty n00b
Joined: 09 Aug 2004 Posts: 2
|
Posted: Mon Aug 09, 2004 8:21 am Post subject: Smartyvalidate on dynamic forms? |
|
|
I have a CMS within which I have created a form generator whereby the CMS users can create forms on the fly for their web site. For validation I wanted to use Smartyvalidate which I never used before. I run into some problems.
First of all the form fields are build dynamically from the DB and assigned to an array.
I loop through this array within the template here is the example for a standard input field
<!--form rows-->
{section name=val loop=$form}
{if $form[val].type=="text"}
<tr>
<td>{$form[val].name} {$form[form1].mandatory}</td>
<td>
<input name="{$form[val].fieldName}" type="{$form[val].type}" value="{$form[val].value}" size="{$form[val].size}" maxlength="{$form[val].maxlength}">
{validate field="$form[val].fieldName" criteria="notEmpty" message="cannot be empty"}
</td>
</tr>
{/if}
{/section}
I wanted to build the validation dynamically as displayed above, automatically checking the field in question. If I put the name for the field directly in the field value it works fine!!!
Secondly there appears to be a caching problem as the message isn't updated if I modifiy it in the code!
Any ideas? It's probably something stupid. Thanks. |
|
Back to top |
|
Smartyeater Smarty n00b
Joined: 09 Aug 2004 Posts: 2
|
Posted: Mon Aug 09, 2004 9:08 am Post subject: |
|
|
It looks as if the original problem is also caused by Caching, But I still have problems within the displaying of the messages...
I want to validate the field $form[val].fieldName based on the criteria returned from the DB $form[val].criteria and return the message value
$form[val].message
i.e.
{validate field="$form[val].fieldName" criteria="$form[val].criteria" message="$form[val].message"}
When I try this I always get back
'Array.message' as the error message
If I put plain text in the field it returns the error correctly!
The $form[val].message array value Does exists and I can print in within the template but it just doestn't return within the validation! What am I doing wrong? |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Mon Aug 09, 2004 9:25 am Post subject: |
|
|
it should read:
{validate field=$form[val].fieldName criteria=$form[val].criteria message=$form[val].message} |
|
Back to top |
|
|
|
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
|