ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button
Article:
  PHP Form Handling
Subject:   mod to 'print a radio button or checkbox'
Date:   2006-08-11 08:08:32
From:   harley1387
Can alternatively use this function that will allow for multiselect checkboxes too. Will need to modify the form handling to process these elements as an array.


//print a radio button or checkbox
function input_radiocheck($type, $element_name, $values, $element_value) {
print '<input type="' . $type . '" name="' . $element_name .'[]" value="' . $element_value . '" ';
if (in_array($element_value , $values[$element_name])) {
print ' checked="checked"';
}
print '/>';
}


Usage:
input_radiocheck('checkbox','contact', $_POST, 'email');
input_radiocheck('checkbox','contact', $_POST, 'mail');
input_radiocheck('checkbox','contact', $_POST, 'phone');