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

form validation array/Redisplay array after submission

 
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
netmastan
Smarty Regular


Joined: 02 Jul 2004
Posts: 64

PostPosted: Mon Dec 20, 2004 6:01 am    Post subject: form validation array/Redisplay array after submission Reply with quote

Well, I am about to finish online booking processing.

I am stack with the following problem.

I have adult_fname as an array.I want to validate it. I want to display the submit value if the any of the field is empty. It just display as an array() .


Let say there are 3 input boxes with name adult_fname[], if u fill in only 2 and left one, it should display error and shows what u typed for other two fileds.

Its the same concept as single variable. let say u have phone and name input box. And they are compulsory. If u just fill in name, it shows error and redisplay what u typed for name field . But what u do when u have array , how do u redisplay it..




Code:

   {if $adult <>"0"}
{validate field="adult_fname" criteria="notEmpty"  transform="trim" message=" * Please enter adult's name."}

   <fieldset><legend>Adult(s) name</legend>
   <table width=100%>
   {section name="myLoop" start=0 loop=$adult}
   <tr><td> First Name : <input type="text" name="adult_fname[]" size="20"  [color=red]value="{$adult_fname|escape}"[/color]></td><td>Last Name : <input type="text" name="adult_lname[]" size="20"></td></tr>
   {/section}
   </table>
   </fieldset>
   {/if}

Back to top
View user's profile Send private message
netmastan
Smarty Regular


Joined: 02 Jul 2004
Posts: 64

PostPosted: Mon Dec 20, 2004 7:03 pm    Post subject: Reply with quote

Any help... ?
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Mon Dec 20, 2004 7:39 pm    Post subject: Reply with quote

You should be able to validate an array of data and it will fail if one is empty, however you will have only one error message. A custom validator could be written to distinguish separate error messages. As for redrawing the form, that is a matter of looping over the array and displaying them, or just doing it statically:

<input type=text name=foobar[] value="{$foobar[0]|escape}">
<input type=text name=foobar[] value="{$foobar[1]|escape}">
<input type=text name=foobar[] value="{$foobar[2]|escape}">
Back to top
View user's profile Send private message Visit poster's website
netmastan
Smarty Regular


Joined: 02 Jul 2004
Posts: 64

PostPosted: Tue Dec 21, 2004 4:30 am    Post subject: Reply with quote

Thank you. I want to display dynamically,

Code:

{if $adult <>"0"
{section name="myLoop" start=0 loop=$adult}
First Name : <input type="text" name="adult_fname[]" size="20"  value="{$adult_fname[{$start}]|escape}">
   {/section}
{/if}


instead of
Code:

{if $adult <>"0"
First Name : <input type="text" name="adult_fname[]" size="20"  value="{$adult_fname[0]|escape}">
First Name : <input type="text" name="adult_fname[]" size="20"  value="{$adult_fname[1]|escape}">
First Name : <input type="text" name="adult_fname[]" size="20"  value="{$adult_fname[2]|escape}">

{/if}



Because number of $adult is some time 1, some time 5 .. it can be anything..
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Tue Dec 21, 2004 5:30 am    Post subject: Reply with quote

You want something like this:

Code:
{section name="myLoop" loop=$adult_fname}
First Name : <input type="text" name="adult_fname[]" size="20"  value="{$adult_fname[myLoop]|escape}">
{/section}
Back to top
View user's profile Send private message Visit poster's website
netmastan
Smarty Regular


Joined: 02 Jul 2004
Posts: 64

PostPosted: Tue Dec 21, 2004 10:05 am    Post subject: Thank you .. Reply with quote

Thank you very much sir. It works now.
Very Happy
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