示例#1
0
 function uio($id, $args = [], $callback = null)
 {
     return \UI::create($id, $args, $callback);
 }
示例#2
0
class UI
{
    function create($data = array(), $start_form_tag = false, $form_start_data = array())
    {
        if (empty($data)) {
            return false;
        }
        $form = "";
        if ($start_form_tag && !empty($form_start_data)) {
            $form .= "<form action='{$form_start_data['action']}' method='{$form_start_data['method']}' >" . PHP_EOL;
            //<form action="" method="POST">
        }
        $data = array_filter($data);
        // Remove Empty Elements Item
        foreach ($data as $val) {
            $form .= "<input ";
            foreach ($val as $k => $v) {
                $form .= "{$k}='{$v}' ";
            }
            $form .= "/>" . PHP_EOL;
        }
        if ($start_form_tag && !empty($form_start_data)) {
            $form .= "</form>" . PHP_EOL;
        }
        return $form;
    }
}
$form = new UI();
$data = [["type" => "text", "name" => "firstname", "id" => "", "class" => "", "required" => "required", "placeholder" => "First Name"], ["type" => "text", "name" => "lastname", "id" => "", "class" => ""], ["type" => "email", "name" => "email", "id" => "", "class" => "", "required" => "required"], ["type" => "submit", "name" => "submit", "id" => "", "class" => "btn btn-default", "value" => "Go"], []];
echo $form->create($data, true, ['action' => '', 'method' => 'POST']);