Last active
December 29, 2015 09:28
-
-
Save KimiyukiYamauchi/7650014 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//print a text box | |
function input_text($element_name, $values) { | |
print '<input type="text" name="' . $element_name .'" value="'; | |
print h($values[$element_name]) . '">'; | |
} | |
//print a submit button | |
function input_submit($element_name, $label) { | |
print '<input type="submit" name="' . $element_name .'" value="'; | |
print h($label) .'"/>'; | |
} | |
//print a textarea | |
function input_textarea($element_name, $values) { | |
print '<textarea name="' . $element_name .'">'; | |
print h($values[$element_name]) . '</textarea>'; | |
} | |
//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 ($element_value == $values[$element_name]) { | |
print ' checked="checked"'; | |
} | |
print '/>'; | |
} | |
//print a <select> menu | |
function input_select($element_name, $selected, $options, $multiple = false) { | |
// print out the <select> tag | |
print '<select name="' . $element_name; | |
// if multiple choices are permitted, add the multiple attribute | |
// and add a [] to the end of the tag name | |
if ($multiple) { print '[]" multiple="multiple'; } | |
print '">'; | |
// set up the list of things to be selected | |
$selected_options = array(); | |
if ($multiple) { | |
foreach ($selected[$element_name] as $val) { | |
$selected_options[$val] = true; | |
} | |
} else { | |
$selected_options[ $selected[$element_name] ] = true; | |
} | |
var_dump($selected_options); | |
// print out the <option> tags | |
foreach ($options as $option => $label) { | |
print '<option value="' . h($option) . '"'; | |
if ($selected_options[$option]) { | |
print ' selected="selected"'; | |
} | |
print '>' . h($label) . '</option>'; | |
} | |
print '</select>'; | |
} | |
function h($str){ | |
return htmlentities($str, ENT_QUOTES, 'UTF-8'); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment