Code for Artists - Miles DeCoster

Use PHP to add radio buttons

Male
Female

Morning
Afternoon
Evening
Night


This version adds a conditional to the function to see if the form has been submitted and if it has “remembers” the selections after the submission.

<?php 
	function make_radios($name, $value) {
		echo '<input type="radio" name="'.$name.'" value="'.$value.'"';
	if (isset($_POST[$name]) && ($_POST[$name] == $value)) {
		echo ' checked="checked"';
	} 
		echo " /> $value ";
	}
?>

<form action="" method="post">
<?php make_radios("Gender","Male"); ?>
<?php make_radios("Gender","Female"); ?>
<?php make_radios("time","Morning"); ?>
<?php make_radios("time","Afternoon"); ?>
<?php make_radios("time","Evening"); ?>
<?php make_radios("time","Night"); ?>
</form>