problem with seting default variable in a php form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
orangeapple
Forum Commoner
Posts: 70
Joined: Tue Jan 06, 2004 1:24 pm
Location: Geneva / Switzerland

problem with seting default variable in a php form

Post 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 !
User avatar
doggy
Forum Commoner
Posts: 80
Joined: Tue Dec 09, 2003 5:01 am
Location: South Africa

Post 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>";
}
?>
Post Reply