Page 1 of 1

problem with seting default variable in a php form

Posted: Wed Feb 25, 2004 12:09 am
by orangeapple
Hi there !

i would like to set default values in a php form. It is easy for normal fields :

Code: Select all

<input type="text" name="firstname" size="24" maxlength="20" value="$firstname">
but how can i set default values for radio buttons and option choices :


Code: Select all

<select name="privilege" size="1">
                                                                                                                                                                        <option value="3">customer</option>
                                                                                                                                                                        <option value="2">owner</option>
                                                                                                                                                                        <option value="1">administrator</option>
                                                                                                                                                                </select>
and

Code: Select all

<input type="radio" value="male" name="sex" checked></td>
                                                                                                                                                        <td width="36" height="26" align="left" xpos="226" content valign="top" csheight="23">
                                                                                                                                                                <div align="left">
                                                                                                                                                                        <font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular" size="2">male</font></div>
                                                                                                                                                        </td>
                                                                                                                                                        <td width="2" height="26"></td>
                                                                                                                                                        <td width="20" height="26" valign="top" align="left" xpos="264"><input type="radio" value="female" name="sex"></td>
who can help ? Thanks !

Posted: Wed Feb 25, 2004 12:20 am
by doggy

Code: Select all

<?php
if ($value == "true") {
echo "<input type="radio" value="male" name="sex" checked>";
echo "<input type="radio" value="female" name="sex">";
} else {
echo "<input type="radio" value="male" name="sex">";
echo "<input type="radio" value="female" name="sex" checked>";
}
?>