Hey guy thanks for the help i fix all my error here is the finished product:
<?php
/*
Form creator class
createForm.php
*/
class createForm
{
private $elements;
private $radio_value;
private $checkbox_value;
//Start a form the HTML Form tag
function startForm($name,$action,$method) {
$this->elements[] = array('type' => 'form',
'name' => $name,
'method' => $method,
'action' => $action);
}
//Creates a Text Field
function addText($type ='text',$name,$size,$maxlength,$vaule){
$this->elements[] = array('type' => $type,
'name' => $name,
'size' => $size,
'maxlength' => $maxlength,
'vaule' => $vaule);
}
//Creates a Text area
function addTextArea($name,$cols='',$rows='',$value){
$this->elements[] = array ('type' => 'textarea',
'name' => $name,
'cols' => $cols,
'rows' => $rows,
'value' => $value);
}
//Submit Button
function addSubmit($type ='submit',$name='Submit',$value = 'Submit') {
$this->elements[] = array('type' => $type,
'name' => $name,
'value' => $value);
}
//Radio Buttons
function addRadio($name,$value){
$this->radio_value = $value;
$this->elements[] = array('type' => 'radio',
'name' => $name);
}
//Check Boxs
function addCheckbox($name,$value){
$this->checkbox_value = $value;
$this->elements[] = array('type' => 'checkbox',
'name' => $name);
}
//Returns the complete form
function completeForm() {
$output = ''; // Initialize variable
foreach ($this->elements as $key => $value)
{
//Switch check for each case in array
switch ($value['type'])
{
case 'form':
$output .= "<form name=\"".$value['name']."\"" ;
$output .= "method=\"".$value['method']."\"" ;
$output .= "action=\"".$value['action']."\">";
$output .= "<br>";
break;
case 'text':
$output .= "<input name=\"".$value['name']."\" ";
$output .= "type=\"".$value['type']."\" value=\"".$value['vaule']."\" ";
$output .= "size=\"".$value['size']."\" maxlength=\"".$value['maxlength']."\">";
$output .= "<br>";
break;
case 'textarea':
$output .= "<textarea name=\"".$value['name']."\"";
$output .= "cols=\"".$value['cols']."\"";
$output .= "rows=\"".$value['rows']."\">$value[value]</textarea>";
$output .= "<br>";
break;
case 'password':
$output .= "<input name=\"".$value['name']."\" ";
$output .= "type=\"".$value['type']."\" value=\"".$value['vaule']."\" ";
$output .= "size=\"".$value['size']."\" maxlength=\"".$value['maxlength']."\">";
$output .= "<br>";
break;
case 'radio':
//Count array for loop
$num = count($this->radio_value);
for($i=0; $i<$num; ) {
foreach($this->radio_value as $label => $v) {
$output .= "<label><input type=\"radio\" name=\"".$value['name']."\"";
$output .= "value=\"$v\">$label</label><br>";
$i++;
}
$output .= "<br>";
}
break;
case 'checkbox':
//Count array for loop
$num = count($this->checkbox_value);
for($i=0; $i<$num; ) {
foreach($this->checkbox_value as $label => $v) {
$output .= "<label><input type=\"checkbox\" name=\"".$value['name']."\"";
$output .= "value=\"$v\">$label</label><br>";
$i++;
}
$output .= "<br>";
}
break;
case 'submit':
$output .= "<input type=\"".$value['type']."\" ";
$output .= "name=\"".$value['name']."\" value=\"".$value['value']."\">";
$output .= "<br>";
break;
}
}
//Outputs html Form end tag
$output .= "</form>";
return $output;
}
}
$radioButtons = array(
"one" => 1,
"two" => 2,
"three" => 3,
"seventeen" => 17 );
$form = new createForm();
$form->startForm('igor','index.php','post');
$form->addText('text','first','33','20','Vitaly Got it to work');
$form->addTextArea('Vitaly','','','Hello');
$form->addRadio('Stuff',$radioButtons);
$form->addCheckbox('stuff2',$radioButtons);
$form->addSubmit();
//Prints the form
echo $form->completeForm();
?>