PHP code example of mathsgod / formkit-php

1. Go to this page and download the library: Download mathsgod/formkit-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mathsgod / formkit-php example snippets



$schema = new FormKit\Schema();
$schema->appendHTML("<form-kit label='hello' type='text'/>");
echo json_encode($schema, JSON_PRETTY_PRINT);


$schema = new FormKit\Schema();
$schema->appendElement("div")->appendElement("span")->appendHTML("hello");
echo json_encode($schema, JSON_PRETTY_PRINT);


$schema = new FormKit\Schema();
$card=$schema->appendComponent("q-card");
$card->setAttribute("flat","");

echo json_encode($schema, JSON_PRETTY_PRINT);
    


$schema = new FormKit\Schema();
$schema->registerClass("q-card", FormKit\Component::class);
$schema->appendHTML("<q-card flat>Hello</q-card>");

echo json_encode($schema, JSON_PRETTY_PRINT);


$schema = new FormKit\Schema();
$schema->registerInputClass("my-input", FormKit\FormKitInputs::class);
$schema->appendHTML("<form-kit label='My custom input' type='my-input'/>");
echo json_encode($schema, JSON_PRETTY_PRINT);


class QBtn extends FormKit\Component
{

    public function setLabel($label)
    {
        $this->setAttribute("label", $label);
    }
}

$schema = new FormKit\Schema();
$schema->registerClass("q-btn", QBtn::class);
$node=$schema->appendHTML("<q-btn label='Hello'/>")[0]; //$node=$schema->appendComponent("q-btn");

//change label
$node->setLabel("World");

echo json_encode($schema, JSON_PRETTY_PRINT);


$schema = new FormKit\Schema();
$e = $schema->appendHTML("<div></div>")[0];
$e->append($schema->createElement("div", "hello"));
echo json_encode($schema, JSON_PRETTY_PRINT);


$schema = new FormKit\Schema();
$e = $schema->appendHTML("<div></div>")[0];
$e->appendHTML("<div>hello</div>");
echo json_encode($schema, JSON_PRETTY_PRINT);



$group = $schema->appendHTML("<form-kit type='group'/>")[0];
$group->setAttribute(":value", json_encode([
    "cities" => ["Hong Kong", "Taiwan", "China"]
]));

$div = $group->appendElement("div");

$div->for(["item", "key", '$value.cities']);

$div->appendHTML('$item');

echo json_encode($schema, JSON_PRETTY_PRINT);

bash
composer