<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>{html_radios}</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.html.options.html" title="{html_options}"> <link rel="next" href="language.function.html.select.date.html" title="{html_select_date}"> </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_radios}</th></tr> <tr> <td width="20%" align="left"> <a accesskey="p" href="language.function.html.options.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.select.date.html">Next</a> </td> </tr> </table> <hr> </div> <div class="sect1" title="{html_radios}"> <div class="titlepage"><div><div><h2 class="title" style="clear: both"> <a name="language.function.html.radios"></a>{html_radios}</h2></div></div></div> <p> <code class="varname">{html_radios}</code> is a <a class="link" href="language.custom.functions.html" title="Chapter 8. Custom Functions">custom function</a> that creates a HTML radio button group. It also takes care of which item is 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>radio</em></span></td> <td>Name of radio 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 radio 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 radio buttons</td> </tr> <tr> <td align="center">selected</td> <td align="center">string</td> <td align="center">No</td> <td align="center"><span class="emphasis"><em>empty</em></span></td> <td>The selected radio element</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 radio 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 radio tags to an array instead of 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 output as name/value-pairs inside each of the created <code class="literal"><input></code>-tags. </p></li> </ul></div> <div class="example"> <a name="id3070870"></a><p class="title"><b>Example 8.16. {html_radios} first example</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_radios name='id' values=$cust_ids output=$cust_names selected=$customer_id separator='<br />'} </pre> </div> </div> <br class="example-break"><div class="example"> <a name="id3070906"></a><p class="title"><b>Example 8.17. {html_radios} second example</b></p> <div class="example-contents"> <pre class="programlisting"> <?php $smarty->assign('cust_radios', array( 1000 => 'Joe Schmoe', 1001 => 'Jack Smith', 1002 => 'Jane Johnson', 1003 => 'Charlie Brown')); $smarty->assign('customer_id', 1001); ?> </pre> <p> Where template is: </p> <pre class="programlisting"> {html_radios name='id' options=$cust_radios selected=$customer_id separator='<br />'} </pre> <p> Both examples will output: </p> <pre class="screen"> <label for="id_1000"> <input type="radio" name="id" value="1000" id="id_1000" />Joe Schmoe</label><br /> <label for="id_1001"><input type="radio" name="id" value="1001" id="id_1001" checked="checked" />Jack Smith</label><br /> <label for="id_1002"><input type="radio" name="id" value="1002" id="id_1002" />Jane Johnson</label><br /> <label for="id_1003"><input type="radio" name="id" value="1003" id="id_1003" />Charlie Brown</label><br /> </pre> </div> </div> <br class="example-break"><div class="example"> <a name="id3070957"></a><p class="title"><b>Example 8.18. {html_radios} - 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, name, email, contact_type_id ' .'from contacts where contact_id='.$contact_id; $smarty->assign('contact',$db->getRow($sql)); ?> </pre> <p> The variable assigned from the database above would be output with the template: </p> <pre class="programlisting"> {html_radios 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.checkboxes.html" title="{html_checkboxes}"><code class="varname">{html_checkboxes}</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.html.options.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.select.date.html">Next</a> </td> </tr> <tr> <td width="40%" align="left" valign="top">{html_options} </td> <td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td> <td width="40%" align="right" valign="top"> {html_select_date}</td> </tr> </table> </div> </body> </html>