Example #1
0
 static function get_form($name, $value = '', $type_form = '')
 {
     //to move to Database Object
     if (isset(static::$form_properties)) {
         $form = new Form();
         //   static:: get_form_properties();
         //    var_dump(static::$form_properties);
         //  $vars=static::$form_properties[$name];
         if ($type_form) {
             $vars = static::get_form_properties_search($name);
             $form->form_format_type = $form::FORM_HORIZONTAL;
         } else {
             $vars = static::get_form_properties($name);
             $form->form_format_type = $form::FORM_HORIZONTAL;
         }
         $type_exception = array('radio', 'checkbox', 'textarea');
         //must be one of the following input to use ->text() todo checkbox
         $type_no_exception = array("text", 'password', 'email', 'select', 'search', 'date', 'datetime', 'datetime-local', 'color', 'button', 'file', 'hidden', 'image', 'month', 'number', 'range', 'reset', 'search', 'submit', 'tel', 'file', 'url', 'selectchosen');
         $type_text = array("text", 'password', 'email', 'search', 'date', 'datetime', 'datetime-local', 'color', 'button', 'file', 'hidden', 'image', 'month', 'number', 'range', 'reset', 'search', 'submit', 'tel', 'url');
         $type = $vars['type'];
         //    var_dump($vars);
         if (in_array($type, $type_no_exception)) {
             foreach ($vars as $attr => $val) {
                 $form->{$attr} = $val;
             }
         } elseif ($type == "radio") {
             foreach ($vars as $attr => $val) {
                 if (is_array($val)) {
                     foreach ($val as $attr2 => $val2) {
                         $form->radio[(int) $attr] = $val;
                         //                        $form->radio[$attr] = $val;
                     }
                 } else {
                     $form->radio[(int) $attr] = $val;
                 }
             }
         } elseif ($type == "textarea") {
             foreach ($vars as $attr => $val) {
                 $form->{$attr} = $val;
             }
         } elseif ($type == "combox") {
             //todo need to add forms
         } else {
         }
         //to do
         if (!empty($value) || (int) $value === 0) {
             $form->value = $value;
         } else {
             if ($type == "number") {
                 $form->value = 0;
             }
         }
         $output = "";
         //var_dump($form);
         //var_dump($type);
         //var_dump($value) ;
         if (in_array($type, $type_text)) {
             $output = $form->text();
         } elseif ($type == "radio") {
             $output = $form->radio();
         } elseif ($type == "select") {
             $output = $form->select();
         } elseif ($type == "selectchosen") {
             $output = $form->selectchosen();
         } elseif ($type == "textarea") {
             $output = $form->textarea();
         } else {
         }
     } else {
         $output = "no form properties set";
     }
     // unset($form);
     return $output;
 }