Skip to content

Instantly share code, notes, and snippets.

@finalwebsites
Created March 29, 2016 06:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save finalwebsites/0c7479c48749d3a71acf to your computer and use it in GitHub Desktop.
Save finalwebsites/0c7479c48749d3a71acf to your computer and use it in GitHub Desktop.
Create form fields with PHP
<?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