Search code examples
htmlradio-buttonsmartyprestashop

Smarty {html_radio} how to make it required?


I'm looking for how to make a radio-buttons group required using the smarty custom function {html_radio} http://www.smarty.net/docs/en/language.function.html.radios.tpl

Here is my code :

{html_radios name='radio' options=$radio_options separator='<br />'}

Thank you.


Solution

  • Digged into function.html_radios.php from tools/smarty/ and saw the $extra var.

    if (!is_array($_val)) {
       $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"';
    }
    

    Also, in http://www.smarty.net/docs/en/language.function.html.radios.tpl, see the "strict" attribute.

    So, my code looks like :

    {html_radios required='required' name='radio' options=$radio_options separator='<br />'}
    

    And it works great.