php - How to assign values from associative array to check boxes using foreach in smarty? -
i'm assigning array named $users_criteria smarty template. array follows:
$users_criteria = array( 1 => array( 'label' => 'registered users', 'condition' => 'date_range' ), 2 => array( 'label' => 'logged-in users', 'condition' => 'date_range' ), 3 => array( 'label' => 'not logged-in users', 'condition' => 'date_range' ), 4 => array( 'label' => 'never logged-in users' ), 5 => array( 'label' => 'package purchase', 'condition' => 'package_type' ), 6 => array( 'label' => 'try demo packages', 'condition' => 'demo_packages' ) ); $smarty->assign('users_criteria', $users_criteria); $file_to_show = 'contact-list-import.tpl';
now there 6 checkboxes in template , want assign label values above array value attribute of each checkbox. each checkbox should have single value above array. in short requirement is: key having value 1 above array should mapped checkbox having name registered_users, key having value 2 above array should mapped checkbox having name logged_in_users,...similar in manner 6 check boxes. tried achieve repetitive combinations of check boxes got. code follows:
{foreach from=$users_criteria key=myid item=criteria} <tr height="30"> <td align="left" width="20%"> <input type="checkbox" class="user_checkbox" name="user_checkbox" id="registered_users" value="{$criteria.label}"/>registered users </td> <td valign="middle" align="left" width="10%"><b>from date </b> : </td> <td align="left" > <input type="text" style="width:100px;" class="inputfield" name="registered_users_from_date" id="registered_users_from_date" maxlength="10" width="20%"></td> <td valign="middle" align="left" width="10%"><b>to date </b> : </td> <td> <input type="text" style="width:100px;" class="inputfield" name="registered_users_to_date" id="registered_users_to_date" maxlength="10" width="20%"></td> </tr> <tr><td colspan="5"> </td></tr> <tr height="30"> <td align="left" width="20%"> <input type="checkbox" class="user_checkbox" name="user_checkbox" id="logged_in_users" value="{$criteria.label}"/>logged-in users </td> <td valign="middle" align="left" width="10%"><b>from date </b> : </td> <td align="left" > <input type="text" style="width:100px;" class="inputfield" name="registered_users_from_date" id="logged_in_users_from_date" maxlength="10"></td> <td valign="middle" align="left" width="10%"><b>to date </b> : </td> <td> <input type="text" style="width:100px;" class="inputfield" name="registered_users_to_date" id="logged_in_users_to_date" maxlength="10"></td> </tr> <tr><td colspan="5"> </td></tr> <tr height="30"> <td align="left" width="20%"> <input type="checkbox" class="user_checkbox" name="user_checkbox" id="not_logged_in_users" value="{$criteria.label}"/>not logged-in users </td> <td valign="middle" align="left" width="10%"><b>from date </b> : </td> <td align="left" > <input type="text" style="width:100px;" class="inputfield" name="not_logged_in_users_from_date" id="not_logged_in_users_from_date" maxlength="10"></td> <td valign="middle" align="left" width="10%"><b>to date </b> : </td> <td> <input type="text" style="width:100px;" class="inputfield" name="not_logged_in_users_to_date" id="not_logged_in_users_to_date" maxlength="10"></td> </tr> <tr><td colspan="5"> </td></tr> <tr height="30"> <td width="300" colspan="5"> <input type="checkbox" class="user_checkbox" name="user_checkbox" id="never_logged_in_users" value="{$criteria.label}"/>never logged-in users </td> </tr> <tr><td colspan="5"> </td></tr> <tr height="30"> <td width="300" colspan="1"> <input type="checkbox" class="user_checkbox" name="user_checkbox" id="package_purchase" value="{$criteria.label}"/>package purchase </td> <td align="left" colspan="4"> <select name="test_pack_type_id" id="test_pack_type_id"> <option value="">all</option> {if $all_type} {foreach from=$all_type item="type"} <option value="{$type.package_type_id}">{$type.package_type_name}</option> {/foreach} {/if} </select> </td> </tr> <tr><td colspan="5"> </td></tr> <tr height="30"> <td width="300" colspan="5"> <input type="checkbox" class="user_checkbox" name="user_checkbox" id="try_demo_packages" value="try_demo_packages"/>try demo packages </td> </tr> <tr><td colspan="5"> </td></tr> {/foreach}
can correct code in order assign proper values checkboxes using foreach in smarty? in advance.
you can using {section}
tag. giving example.
{section name=i loop=$users_criteria} <tr height="30"> <td align="left" width="20%"> <input type="checkbox" class="user_checkbox" name="user_checkbox" id="registered_users" value="{$users_criteria[i].label}"/>registered users </td> <td valign="middle" align="left" width="10%"><b>from date </b> : </td> <td align="left" > <input type="text" style="width:100px;" class="inputfield" name="registered_users_from_date" id="registered_users_from_date" maxlength="10" width="20%"></td> <td valign="middle" align="left" width="10%"><b>to date </b> : </td> <td> <input type="text" style="width:100px;" class="inputfield" name="registered_users_to_date" id="registered_users_to_date" maxlength="10" width="20%"></td> </tr> <tr><td colspan="5"> </td></tr> {/section}
Comments
Post a Comment