What can I improve in this form builder?  I'm looking for code review, optimization, and best practices.<?php/** * Project: validator - File: form_builder.php * Author: danutz0501 copyright 2014 * Date : (m/y) 06/2014 */class form_builder{    private $form;    public function __construct(){}    public function __toString(){        return $this->form;    }    public function add_node($type, array $args = []){        $this->form .= '<'.$type.' '.$this->setup_args($args).'>'.PHP_EOL;        return $this;    }    public function end_node($type){        $this->form .= '</'.$type.'>'.PHP_EOL;        return $this;    }    public function add_elem($text){        $this->form .= $text.PHP_EOL;        return $this;    }    public function img($data, array $args = []){        $this->form .= '<img src='.$data.' '.$this->setup_args($args).'/>'.PHP_EOL;        return $this;    }    public function start_form(array $args = []){        $this->form .= '<form'.$this->setup_args($args).' >'.PHP_EOL;        return $this;    }    public function end_form(){        $this->form .= '</form>'.PHP_EOL;        return $this;    }    public function input(array $args = []){        $this->form .= '<input'.$this->setup_args($args).$this->value($args).' />'.PHP_EOL;        return $this;    }    public function checkbox(array $args = []){        $result = (count($args)) ? array_merge(['type' => 'checkbox'], $args) : ['type' => 'checkbox'];        $this->input($result);        return $this;    }    public function radio(array $args){        $result = (count($args)) ? array_merge(['type' => 'radio'], $args) : ['type' => 'radio'];        $this->input($result);        return $this;    }    public function textarea(array $args = []){        $this->form .= '<textarea '.$this->setup_args($args).' >'.$this->value($args, false).'</textarea>'.PHP_EOL;        return $this;    }    public function select(array $value, array $args = []){        $this->form .= '<select '.$this->setup_args($args).'>'.PHP_EOL;        foreach($value as $key => $values){            if(is_array($values)){                $this->form .= \t<optgroup label='.$key.'>.PHP_EOL;                    foreach($values as $k => $v)                        $this->form .= $this->populate_select($k, $v);                $this->form .= \t</optgroup>.PHP_EOL;            }else{                $this->form .= $this->populate_select($key, $values);            }        }        $this->form .= '</select>'.PHP_EOL;        return $this;    }    private function populate_select($key, $value){        return \t\t.'<option value='.$key.'>'.ucfirst($value).'</option>'.PHP_EOL;    }    private function value(array $args = [], $type = true){        return (!empty($args['value'])) ? ( $type ? ' value='.$args['value'].' ' : $args['value']): '';    }    private function setup_args(array $args = []){        $str = '';        if(count($args)){            foreach($args as $key => $value){                if($key == 'value')                    continue;                $str .= ' '.$key.'='.$value.' ';            }        }        return $str;    }}Usage:$array = [    'titlul lui optgroup1' => ['xx1'=>'xxx1', 'xx12'=>'xxx2', 'xx11'=>'xxx3'],    'titlul lui optgroup2' => ['xx34' => 'xxx', '00' => 'xxx', 'xx232'=>'xxx1', 'xx43'=>'xxx2', 'xxdfdsf'=>'xxx3']];$array1 = ['val1'=>'xxl', 'xx'=>'xxx1', 'xx1'=>'xxx2', 'xx2'=>'xxx3'];$img = 'data:image/jpeg;base64 .... etc';$form->start_form(['action'=>'index.php', 'method'=>'post'])     ->input(['type'=> 'text', 'name'=>'nume', 'class'=> 'test1 test2', 'value'=>'muhaha'])     ->add_node('div')     ->textarea(['value'=>'merge'])     ->select($array)     ->input(['type'=>'submit', 'value'=>'Trimite'])     ->end_node('div')     ->checkbox()     ->add_elem('text1')     ->checkbox(['class'=>'er4 34 tyd'])    ->add_elem('text2<br />')     ->img($img,['width'=>'200px', 'height'=>'200px'])     ->end_form();echo $form;
Form builder improvment
php