<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>{html_checkboxes}</title> <meta name="generator" content="DocBook XSL Stylesheets V1.75.1"> <link rel="home" href="index.html" title="Smarty Manual"> <link rel="up" href="language.custom.functions.html" title="Chapter 8. Custom Functions"> <link rel="prev" href="language.function.fetch.html" title="{fetch}"> <link rel="next" href="language.function.html.image.html" title="{html_image}"> </head> <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr><th colspan="3" align="center">{html_checkboxes}</th></tr> <tr> <td width="20%" align="left"> <a accesskey="p" href="language.function.fetch.html">Prev</a> </td> <th width="60%" align="center">Chapter 8. Custom Functions</th> <td width="20%" align="right"> <a accesskey="n" href="language.function.html.image.html">Next</a> </td> </tr> </table> <hr> </div> <div class="sect1" title="{html_checkboxes}"> <div class="titlepage"><div><div><h2 class="title" style="clear: both"> <a name="language.function.html.checkboxes"></a>{html_checkboxes}</h2></div></div></div> <p> <code class="varname">{html_checkboxes}</code> is a <a class="link" href="language.custom.functions.html" title="Chapter 8. Custom Functions">custom function</a> that creates an html checkbox group with provided data. It takes care of which item(s) are selected by default as well. </p> <div class="informaltable"><table border="1"> <colgroup> <col align="center"> <col align="center"> <col align="center"> <col align="center"> <col> </colgroup> <thead><tr> <th align="center">Attribute Name</th> <th align="center">Type</th> <th align="center">Required</th> <th align="center">Default</th> <th>Description</th> </tr></thead> <tbody> <tr> <td align="center">name</td> <td align="center">string</td> <td align="center">No</td> <td align="center"><span class="emphasis"><em>checkbox</em></span></td> <td>Name of checkbox list</td> </tr> <tr> <td align="center">values</td> <td align="center">array</td> <td align="center">Yes, unless using options attribute</td> <td align="center"><span class="emphasis"><em>n/a</em></span></td> <td>An array of values for checkbox buttons</td> </tr> <tr> <td align="center">output</td> <td align="center">array</td> <td align="center">Yes, unless using options attribute</td> <td align="center"><span class="emphasis"><em>n/a</em></span></td> <td>An array of output for checkbox buttons</td> </tr> <tr> <td align="center">selected</td> <td align="center">string/array</td> <td align="center">No</td> <td align="center"><span class="emphasis"><em>empty</em></span></td> <td>The selected checkbox element(s)</td> </tr> <tr> <td align="center">options</td> <td align="center">associative array</td> <td align="center">Yes, unless using values and output</td> <td align="center"><span class="emphasis"><em>n/a</em></span></td> <td>An associative array of values and output</td> </tr> <tr> <td align="center">separator</td> <td align="center">string</td> <td align="center">No</td> <td align="center"><span class="emphasis"><em>empty</em></span></td> <td>String of text to separate each checkbox item</td> </tr> <tr> <td align="center">assign</td> <td align="center">string</td> <td align="center">No</td> <td align="center"><span class="emphasis"><em>empty</em></span></td> <td>Assign checkbox tags to an array instead of output</td> </tr> <tr> <td align="center">labels</td> <td align="center">boolean</td> <td align="center">No</td> <td align="center"><span class="emphasis"><em><code class="constant">TRUE</code></em></span></td> <td>Add <label>-tags to the output</td> </tr> </tbody> </table></div> <div class="itemizedlist"><ul class="itemizedlist" type="disc"> <li class="listitem"><p> Required attributes are <em class="parameter"><code>values</code></em> and <em class="parameter"><code>output</code></em>, unless you use <em class="parameter"><code>options</code></em> instead. </p></li> <li class="listitem"><p> All output is XHTML compliant. </p></li> <li class="listitem"><p> All parameters that are not in the list above are printed as name/value-pairs inside each of the created <input>-tags. </p></li> </ul></div> <div class="example"> <a name="id3067900"></a><p class="title"><b>Example 8.9. {html_checkboxes}</b></p> <div class="example-contents"> <pre class="programlisting"> <?php $smarty->assign('cust_ids', array(1000,1001,1002,1003)); $smarty->assign('cust_names', array( 'Joe Schmoe', 'Jack Smith', 'Jane Johnson', 'Charlie Brown') ); $smarty->assign('customer_id', 1001); ?> </pre> <p> where template is </p> <pre class="programlisting"> {html_checkboxes name='id' values=$cust_ids output=$cust_names selected=$customer_id separator='<br />'} </pre> <p> or where PHP code is: </p> <pre class="programlisting"> <?php $smarty->assign('cust_checkboxes', array( 1000 => 'Joe Schmoe', 1001 => 'Jack Smith', 1002 => 'Jane Johnson', 1003 => 'Charlie Brown') ); $smarty->assign('customer_id', 1001); ?> </pre> <p> and the template is </p> <pre class="programlisting"> {html_checkboxes name='id' options=$cust_checkboxes selected=$customer_id separator='<br />'} </pre> <p> both examples will output: </p> <pre class="screen"> <label><input type="checkbox" name="id[]" value="1000" />Joe Schmoe</label><br /> <label><input type="checkbox" name="id[]" value="1001" checked="checked" />Jack Smith</label> <br /> <label><input type="checkbox" name="id[]" value="1002" />Jane Johnson</label><br /> <label><input type="checkbox" name="id[]" value="1003" />Charlie Brown</label><br /> </pre> </div> </div> <br class="example-break"><div class="example"> <a name="id3067987"></a><p class="title"><b>Example 8.10. Database example (eg PEAR or ADODB): </b></p> <div class="example-contents"> <pre class="programlisting"> <?php $sql = 'select type_id, types from contact_types order by type'; $smarty->assign('contact_types',$db->getAssoc($sql)); $sql = 'select contact_id, contact_type_id, contact ' .'from contacts where contact_id=12'; $smarty->assign('contact',$db->getRow($sql)); ?> </pre> <p>The results of the database queries above would be output with.</p> <pre class="programlisting"> {html_checkboxes name='contact_type_id' options=$contact_types selected=$contact.contact_type_id separator='<br />'} </pre> </div> </div> <br class="example-break"><p> See also <a class="link" href="language.function.html.radios.html" title="{html_radios}"><code class="varname">{html_radios}</code></a> and <a class="link" href="language.function.html.options.html" title="{html_options}"><code class="varname">{html_options}</code></a> </p> </div> <div class="navfooter"> <hr> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"> <a accesskey="p" href="language.function.fetch.html">Prev</a> </td> <td width="20%" align="center"><a accesskey="u" href="language.custom.functions.html">Up</a></td> <td width="40%" align="right"> <a accesskey="n" href="language.function.html.image.html">Next</a> </td> </tr> <tr> <td width="40%" align="left" valign="top">{fetch} </td> <td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td> <td width="40%" align="right" valign="top"> {html_image}</td> </tr> </table> </div> </body> </html>