On 07-08-2009 at 15:08:03 Guillaume Lecanu <guilla...@lya.fr> wrote:

Hi again,

I have in my form a field "civility" like that :

            <label>Civility</label>
            <ul>
            <li>
                <input type="radio" name="civility" value="Miss"
id="civility-miss" />
                <label for="civility-miss">Miss</label>
            </li>
            <li>
                <input type="radio" name="civility" value="Ms"
id="civility-ms" />
                <label for="civility-ms">Ms</label>
            </li>
            <li>
                <input type="radio" name="civility" value="Mr"
id="civility-mr"  />
                <label for="civility-mr">Mr</label>
            </li>
            </ul>

If the form is submitted with errors, I need to pre-fill the "civility"
field with the previous selected value.
I give the $_POST array to PHPTAL like that : $tpl->set('P', $_POST), so
I can access to this value by "P/civility"

What is the best way to have no radio-buttons selected if P/civility
doesn't exist, and to have the good radio-button selected dependant of
the value found into P/civility ?

Something like that works:

<ul tal:define="selected_value P/civility | 'Miss'">
<input type="radio" tal:attributes="checked php:selected_value == 'Miss'" value="Miss"/>
</ul>


You might save some typing if you generate all inputs from an array:

<input tal:repeat="value php:array('Miss','Ms','Mr')" type="radio"
tal:attributes="checked php:selected_value == value" value="${value}"/>


--
regards, Kornel

_______________________________________________
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal

Reply via email to