|
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 |
waro Smarty Regular
Joined: 12 Jun 2008 Posts: 38
|
Posted: Wed Jan 27, 2016 2:50 am Post subject: [Solved] How do I generate select form from a multiple array |
|
|
Hi,
If I have an array like below:
Code: | Array
(
[0] => Array
(
[form_type_id] => 1
[form_title] => Full Name
[form_type] => text
[values] => 255
[selections] =>
)
[1] => Array
(
[form_type_id] => 14
[form_title] => Email
[form_type] => text
[values] => 255
[selections] =>
)
[2] => Array
(
[form_type_id] => 54
[form_title] => Test Types
[form_type] => select
[values] => TOEFL,IELTS
[selections] => Array
(
[0] => TOEFL
[1] => Array
(
[selection] => IELTS
)
[] => Array
(
[selection] => TOEFL
)
)
)
[3] => Array
(
[form_type_id] => 58
[form_title] => Degrees
[form_type] => select
[values] => High School, Bachelor, Master, Doctor
[selections] => Array
(
[0] => SMA
[1] => S1
[2] => Array
(
[selection] => SMA
)
[3] => Array
(
[selection] => S1
)
[4] => Array
(
[selection] => S2
)
[5] => Array
(
[selection] => S3
)
)
)
) |
How do I get a template to have an HTML form like below:
Code: | <form method="post" action="process.php">
Full name: <input type="text" name="1">
Email: <input type="text" name="14">
Test type:
<select name="54">
<option value="TOEFL">
<option value="IELTS">
</select>
Degree:
<select name="58">
<option value="High School">
<option value="Bachelor">
<option value="Master">
<option value="Doctor">
</select>
<submit>
</form> |
I tried using nested {section} below but the option value are empty: Code: | {section name=ft loop=$form_types}
{$form_types[ft].form_title}
{if $form_types[ft].form_type eq 'select'}<select name="{$form_types[ft].form_type_id}">{/if}
{if $form_types[ft].form_type eq 'date'}
<input type="text" name="{$form_types[ft].form_type_id}">
{elseif $form_types[ft].form_type eq 'file'}
<input type="file" name="{$form_types[ft].form_type_id}">
{elseif $form_types[ft].form_type eq 'select'}
{section name=fs loop=$form_types[$selections]}
<option value="{$form_types[$selections][fs].selection}"> {$form_types[$selections][fs].selection}
{/section}
{elseif $form_types[ft].form_type eq 'text'}
<input type="text" name="{$form_types[ft].form_type_id}">
{elseif $form_types[ft].form_type eq 'textarea'}
<textarea name="{$form_types[ft].form_type_id}" rows="11"></textarea>
{/if}
{if $form_types[ft].form_type eq 'select'}</select>{/if}
{/section} |
Thank you in advance.
Last edited by waro on Wed Jan 27, 2016 1:46 pm; edited 1 time in total |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Wed Jan 27, 2016 10:48 am Post subject: |
|
|
1. {foreach}
2. There's option list builder tag. |
|
Back to top |
|
waro Smarty Regular
Joined: 12 Jun 2008 Posts: 38
|
Posted: Wed Jan 27, 2016 1:45 pm Post subject: |
|
|
Thank you, you're a life saver.. Both answers are correct |
|
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
|