PHP Code:
<?php
//require the class
require("require/Form_Generator.php");
// First value = destination, second value = method, enctype is autoset.
$form = new form_generator("index.php?ThisIsTheDestination");
// normal text boxes.
$form->textbox("TextBoxname", "TextBox Label", "", "TextBox Placeholder");
$form->textbox("TextBoxname", "TextBox Label", "TextBox Value", "");
// break line
$form->breakline("This is a break line!", "red");
// password textboxes
$form->password("password", "Password", "", "Your Password");
$form->password("rpassword", "Repeat Password", "", "Repeat Your Password");
// break line
$form->breakline("Check if both passwords match!", "blue");
// create selections
$form->select("selectionname", "Selection Label", "Choice1, Choice2, Choice3", "chc1, chc2, chc3");
// create radio buttons
$form->radio("radioname", "Radio Label", "Choice1, Choice2, Choice3", "chc1, chc2, chc3");
// create checkboxes
$form->checkbox("checkboxname", "Checkbox Label", "Choice1, Choice2, Choice3", "chc1, chc2, chc3");
// break line
$form->breakline("Wasn't this usefull?", "green");
// file upload
$form->file("NameofFile", "File Label");
//submit button
$form->submit("Register");
// Create the form.
$form->buildForm();
?>
PHP Code:
<?php
//////////////////////////////
// //
// This class has //
// been created by //
// Jurien Hamaker //
// //
// http://jurienhamaker.net //
// //
// This is a free //
// release //
// //
//////////////////////////////
class form_generator
{
var $destination;
var $method;
var $enctype = '';
var $fmBody = '';
var $fmHeader;
var $fmFooter;
var $form;
var $choices;
var $names;
var $options = '';
public function __construct($destination = '', $method = 'POST')
{
$this->destination = $destination;
$this->method = $method;
}
public function submit($value = "submit", $name = "")
{
$this->fmBody .= '<tr><td></td><td><input type="submit" value="'.$value.'" name="'.$name.'"></td></tr>';
}
public function textbox($name, $label = '', $value = '', $placeholder = '', $color = NULL)
{
$this->fmBody .= '<tr><td><label for="'.$name.'"><font color="'.$color.'">'.$label.': </font></label></td><td><input id="'.$name.'" type="text" name="'.$name.'" value="'.$value.'" placeholder="'.$placeholder.'"></td></tr>';
}
public function password($name, $label = '', $value = '', $placeholder = '', $color = NULL)
{
$this->fmBody .= '<tr><td><label for="'.$name.'"><font color="'.$color.'">'.$label.': </font></label></td><td><input id="'.$name.'" type="password" value="'.$value.'" placeholder="'.$placeholder.'" name="'.$name.'"></td></tr>';
}
public function breakline($tekst = NULL, $color = NULL)
{
$this->fmBody .= '<tr><td colspan="2" style="text-decoration:underline; padding-top:5px; padding-bottom:5px;"><center><font color="'.$color.'">'.$tekst.'</font></center></td></tr>';
}
public function select($name, $label = '', $choices, $names, $color = NULL)
{
$choices = str_replace(" ", "", $choices);
$names = str_replace(" ", "", $names);
$this->choices = explode(",", $choices);
$this->names = explode(",", $names);
$i = 0;
foreach($this->choices as $choice)
{
$this->options .= '<option value="'.$this->names[$i].'">'.$this->choices[$i].'</option>';
$i++;
}
$this->fmBody .= '<tr><td><label for="'.$name.'"><font color="'.$color.'">'.$label.': </font></label></td><td>
<select id="'.$name.'" name="'.$name.'">
'.$this->options.'
</select>
</td></tr>';
}
public function radio($name, $label = '', $choices, $names, $color = NULL)
{
$choices = str_replace(" ", "", $choices);
$names = str_replace(" ", "", $names);
$this->choices = explode(",", $choices);
$this->names = explode(",", $names);
$i = 0;
$this->fmBody .= '<tr><td><label for="'.$name.'"><font color="'.$color.'">'.$label.': </font></label></td><td>';
foreach($this->choices as $choice)
{
$this->fmBody .= '<input type="radio" name="'.$name.'" value="'.$this->names[$i].'"> '.$this->choices[$i].'<br>';
$i++;
}
$this->fmBody .= '</td></tr>';
}
public function checkbox($name, $label = '', $choices, $names, $color = NULL)
{
$choices = str_replace(" ", "", $choices);
$names = str_replace(" ", "", $names);
$this->choices = explode(",", $choices);
$this->names = explode(",", $names);
$i = 0;
$this->fmBody .= '<tr><td><label for="'.$name.'"><font color="'.$color.'">'.$label.': </font></label></td><td>';
foreach($this->choices as $choice)
{
$this->fmBody .= '<input type="checkbox" name="'.$name.'" value="'.$this->names[$i].'"> '.$this->choices[$i].'<br>';
$i++;
}
$this->fmBody .= '</td></tr>';
}
public function file($name, $label = '')
{
$this->enctype = "multipart/form-data";
$this->fmBody .= '<tr><td><label for="'.$name.'"><font color="'.$color.'">'.$label.': </font></label></td><td>
<input id="'.$name.'" type="file" name="'.$name.'">
</td></tr>';
}
public function buildForm()
{
$this->fmHeader = '<table><form method="'.$this->method.'" action="'.$this->destination.'" enctype="'.$this->enctype.'">';
$this->fmFooter = '</form></table>';
$this->form = $this->fmHeader . $this->fmBody . $this->fmFooter;
echo $this->form;
}
}
// end of class.
?>