Hi lad's,
I'm working on a project at the moment that requires alot of forms. I was thinking of a workaround to minimise spending hours of time on the subject. Above all else I don't want to use a framework to do this for me, I'm still learning so its important for me to understand at the core.
Ok so I have a class called form builder, which looks like this:
<?php
class formBuilder extends systemCore{
public $token, $method=array();
public function __construct(){
parent::__construct();
}
public function getFormMethod(&$method, $pop, $filter){//($_POST, true, filterStr)
if($pop == true):
array_pop($method);
endif;
foreach($method as $f => $v){
if(is_array($v)){
$v = implode(',', $v);
}
$this->method[$f] = $filter($v);
}
return $this->method;
}
public function generateToken(){
return $this->token = mt_rand(1, 10000).md5();
}
public function inputField($label, $type, $id, $name, $value, $title, $css, $required){
$required = ($required == true) ? trim('<span color="red">&lowast</span>') : '';
// i know this seems a little redundant
$label = (is_null($label)) ? '' : trim(htmlspecialchars($label, ENT_QUOTES));
$type = (is_null($type)) ? 'text' : trim(htmlspecialchars($type, ENT_QUOTES));
$id = (is_null($id)) ? '' : trim(htmlspecialchars($id, ENT_QUOTES));
$name = (is_null($name)) ? '' : trim(htmlspecialchars($name, ENT_QUOTES));
$value = (is_null($value)) ? '' : trim(htmlspecialchars($value, ENT_QUOTES));
$title = (is_null($title)) ? '' : trim(htmlspecialchars($title, ENT_QUOTES));
$css = (is_null($css)) ? '' : trim(htmlspecialchars($css, ENT_QUOTES));
echo('
<label for="'.$name.'">'.$label.'</label><br />
<input type="'.$type.'" id="'.$id.'" name="'.$name.'" value="'.$value.'" title="'.$title.'" class="'.$css.'">'.$required.'<br />
');
}
//.................and so on
} // end class formBuilder
?>
What do you guys think? Should I just stick to the normal , , etc html display
$form = new formbuilder();
$form->inputField('name', 'text', 'name', 'name', 'my value', 'my title', null, true);
The CSS would be applied the same to both methods so I have not really cut any development time out here so I'm not really sure how I would play this card.
Im just looking to get some other opinions on this, cheers guys.