Skip to content

Instantly share code, notes, and snippets.

@jeremykendall
Created November 12, 2015 20:02
Show Gist options
  • Save jeremykendall/083a833f8c4fee36231e to your computer and use it in GitHub Desktop.
Save jeremykendall/083a833f8c4fee36231e to your computer and use it in GitHub Desktop.
I've come a long way
<?php
function giganti_form_begin ( $name, $action, $method='post', $onSubmit='', $enctype='' ) {
echo "<form name=\"$name\" action=\"$action\" method=\"$method\" onSubmit=\"$onSubmit\" enctype=\"$enctype\">\n";
}
function giganti_form_div ( $formlabel, $formw ) {
echo "<div class=\"row\">\n";
echo "<span class=\"formlabel\">" . $formlabel . "</span>\n";
echo "<span class=\"formw\">" . $formw . "</span>\n";
echo "</div>\n";
}
// The following function returns an input select. You must provide the name for the
// select, the table the select will come from, and the id and label columns.
// Provide a value for $match (that will be a value of $sid) in order to have a certain item pre-selected.
function giganti_db_select ( $sname, $stable, $sid, $slabel, $match='', $extra='', $swhere='' ) {
$squery = "SELECT $sid, $slabel FROM $stable $swhere ORDER BY $slabel";
$sresult = mysql_query($squery)
or die ('Query Error: ' . mysql_error());
echo "<select name=\"$sname\" $extra>\n";
echo "<option>". ucwords($sname) . "\n";
while ($myoption = mysql_fetch_array($sresult)) {
echo "<option value=\"" . $myoption[$sid] . "\"";
if ($myoption[$sid]==$match) {
echo " selected";
}
echo ">" . $myoption[$slabel] . "\n";
}
echo "</select>\n";
}
// The following function returns a select box that will provide a year range. Provide the
// select name, year from, and the function will provide the current year + 1 to your lower year limit.
// Provide a number for $match in order to have a certain year pre-selected.
function giganti_year_select ( $sname, $syto, $match='' ) {
echo "<select name=\"$sname\">\n";
echo "<option>Year\n";
$x = 1;
$i = (date("Y") + 2);
while ($i>$syto) {
$i = $i-$x;
echo "<option value=\"$i\"";
if ($i==$match) {
echo " selected";
}
echo ">$i\n";
}
echo "</select>\n";
}
// The following function returns input checkboxes. You must provide the name for the
// checkboxes, the table the checkboxes will come from, and the id and label columns.
function giganti_db_check ( $cname, $ctable, $cid, $clabel ) {
$cquery = "SELECT $cid AS cid, $clabel FROM $ctable ORDER BY $clabel";
$cresult = mysql_query($cquery)
or die ('Query Error: ' . mysql_error());
while ($mycheck = mysql_fetch_array($cresult)) {
echo "<input type=\"checkbox\" name=\"" . $cname . "[]\" value=\"" . $mycheck["cid"]. "\" ";
echo ">" . $mycheck[$clabel] . "\n";
}
}
// The following function returns input checkboxes. You must provide the name for the
// checkboxes, the table the checkboxes will come from, and the id and label columns.
// Provide a value for $match (that will be a value of $rid) in order to have a certain item pre-selected.
function giganti_db_radio ( $rname, $rtable, $rid, $rlabel, $match='' ) {
$rquery = "SELECT $rid, $rlabel FROM $rtable ORDER BY $rlabel";
$rresult = mysql_query($rquery)
or die ('Query Error: ' . mysql_error());
while ($myradio = mysql_fetch_array($rresult)) {
echo "<input type=\"radio\" name=\"$rname\" value=\"" . $myradio[$rid] . "\"";
if ($myradio[$rid]==$match) {
echo " checked";
}
echo ">" . $myradio[$rlabel] . "\n";
}
}
function giganti_text ( $name, $size=20, $maxlength=80, $value='' ) {
echo "<input type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$maxlength\" value=\"$value\"><br />\n";
}
function giganti_pass ( $name, $size=20, $maxlength=80, $value='' ) {
echo "<input type=\"password\" name=\"$name\" size=\"$size\" maxlength=\"$maxlength\" value=\"$value\"><br />\n";
}
function giganti_hidden ( $name, $value ) {
echo "<input type=\"hidden\" name=\"$name\" value=\"$value\">";
}
function giganti_phone ( $ac='', $ex='', $l='' ) {
echo "( <input type=\"text\" name=\"areacode\" size=\"3\" maxlength=\"3\" value=\"$ac\"> ) <input type=\"text\" name=\"exchange\" size=\"3\" maxlength=\"3\" value=\"$ex\"> - <input type=\"text\" name=\"line\" size=\"4\" maxlength=\"4\" value=\"$l\"><br />\n";
}
function giganti_date ( $ydisplay=0, $tstamp='' ) {
if ($ydisplay == 1) {
$m = '';
$d = '';
$y = date("Y");
} elseif ($tstamp <> '') {
$m = date("m", $tstamp);
$d = date("d", $tstamp);
$y = date("Y", $tstamp);
} else {
$m = '';
$d = '';
$y = '';
}
echo "<input type=\"text\" name=\"month\" size=\"2\" maxlength=\"2\" value=\"$m\"> / <input type=\"text\" name=\"day\" size=\"2\" maxlength=\"2\" value=\"$d\"> / <input type=\"text\" name=\"year\" size=\"4\" maxlength=\"4\" value=\"$y\"><br />\n";
}
function giganti_submit ( $name, $value='Submit', $click='' ) {
echo "<input type=\"submit\" name=\"$name\" value=\"$value\" onClick=\"$click\">\n";
}
function giganti_submit_disabled ( $name, $value ) {
echo "<input type=\"submit\" name=\"$name\" value=\"$value\" disabled>\n";
}
function giganti_form_end () {
echo "</form>\n";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment