Fast html / php forms?

I am currently working on a project that requires many forms. I was thinking of a workaround to minimize time expenses. First of all, I don’t want to use the framework to do this for me, I’m still learning so that it’s important for me to understand the point.

So, I have a class called form builder that 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 with the usual, etc. Html mappings

$form = new formbuilder();
$form->inputField('name', 'text', 'name', 'name', 'my value', 'my title', null, true);

CSS will be applied the same way for both methods, so I have not really reduced the development time, so I’m not quite sure how I will play on this map.

I just want other opinions on this, welcome guys.

+3
3

, . PHP-, . , Ruby on Rails, , - /. PHP, , Cake.

, , HTML. , FormBuilder, ?

, , , .. ( SQL, ).

. , , . , , . , , , .

, , . , . . HTML ( ), PHP . , ? . , .

, , .. - . CakePHP. , / , . , , , , -, ( ).

+2

, , , .:)

, . , (, ) , - ( ). HTML .

, . Abstract .

- . , , . ?

? , ? , ? ? , . - , .

. , , , , , , ?

+2

- . , , . , , , , , .

, , , , .

Phorms, , , , , - , , , , .

, , , , , , , .

,

+2

Source: https://habr.com/ru/post/1751843/


All Articles