Created
March 29, 2016 06:09
-
-
Save finalwebsites/0c7479c48749d3a71acf to your computer and use it in GitHub Desktop.
Create form fields with PHP
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 | |
function create_form_field($formelement, $label = "", $db_value = "", $length = 25) { | |
$form_field = ($label != "") ? "<label for=\"".$formelement."\">".$label."</label>\n" : ""; | |
$form_field .= " <input name=\"".$formelement."\" type=\"text\" size=\"".$length."\" value=\""; | |
if (isset($_REQUEST[$formelement])) { | |
$form_field .= $_REQUEST[$formelement]; | |
} elseif (isset($db_value) && !isset($_REQUEST[$formelement])) { | |
$form_field .= $db_value; | |
} else { | |
$form_field .= ""; | |
} | |
$form_field .= "\">\n"; | |
return $form_field; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment