Skip to content

Instantly share code, notes, and snippets.

@hawksprite
Created January 2, 2014 06:01
Show Gist options
  • Save hawksprite/8215599 to your computer and use it in GitHub Desktop.
Save hawksprite/8215599 to your computer and use it in GitHub Desktop.
<?php
class Forms
{
private static $initialized = false;
private static function initialize()
{
if (self::$initialized)
return;
self::$initialized = true;
}
// The bread and butter of the class. This is used to create a quick form.
// We're using this to generate forms for the administration section of a web-portal. So it's quick to deploy a more user-friendly way
// to interact with our database and API.
public static function buildForm($id, $target, $names, $types, $ids)
{
// Put this at the start of each function, making sure we can just call it as a global class but it needs initalized on it's first run
self::initialize();
$buffer = "";
// Initialize the markup for the form
$buffer .= '<form action = "' . $target . '" method="POST" id="' . $id . '" class="form-horizontal">';
// Add each input item
for ($i = 0; $i < sizeof($names); $i++)
{
$label = $names[$i];
$type = $types[$i];
$input_id = $ids[$i];
$buffer .= '<div class = "control-group">';
$buffer .= '<label class = "control-label">' . $label . '</label>';
$buffer .= '<div class="controls">';
$buffer .= '<input type = "' . $type . '" id="' . $input_id . '" name="' . $input_id . '" class="input-large" />';
$buffer .= '</div><br>';
}
// Add our hidden caller in
$buffer .= '<input type = "hidden" name="caller" id="caller" value="' . $id . '">';
// Finsh off the form with the submit button
$buffer .= '<div class="form-actions"><button type="submit" class="btn blue"><i class="icon-ok"></i> Submit</button></div></form>';
// Return the buffer
return $buffer;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment