A PHP library for generating FormKit Schema from PHP classes.
Install via composer:
composer require mathsgod/formkit-php$schema = new FormKit\Schema();
$schema->appendHTML("<form-kit label='hello' type='text'/>");
echo json_encode($schema, JSON_PRETTY_PRINT);output:
[
{
"$formkit": "text",
"label": "hello"
}
]$schema = new FormKit\Schema();
$schema->appendElement("div")->appendElement("span")->appendHTML("hello");
echo json_encode($schema, JSON_PRETTY_PRINT);output:
[
{
"$el": "div",
"children": [
{
"$el": "span",
"children": [
"hello"
]
}
]
}
]$schema = new FormKit\Schema();
$card=$schema->appendComponent("q-card");
$card->setAttribute("flat","");
echo json_encode($schema, JSON_PRETTY_PRINT);
output:
[
{
"$cmp": "q-card",
"props": {
"flat": true
}
}
]$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);output:
[
{
"$cmp": "q-card",
"props": {
"flat": true
},
"children": [
"Hello"
]
}
]$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);output:
[
{
"$formkit": "my-input",
"label": "My custom input"
}
]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);output:
[
{
"$cmp": "q-btn",
"props": {
"label": "World"
}
}
]$schema = new FormKit\Schema();
$e = $schema->appendHTML("<div></div>")[0];
$e->append($schema->createElement("div", "hello"));
echo json_encode($schema, JSON_PRETTY_PRINT);output:
[
{
"$el": "div",
"children": [
{
"$el": "div",
"children": [
"hello"
]
}
]
}
]$schema = new FormKit\Schema();
$e = $schema->appendHTML("<div></div>")[0];
$e->appendHTML("<div>hello</div>");
echo json_encode($schema, JSON_PRETTY_PRINT);output:
[
{
"$el": "div",
"children": [
{
"$el": "div",
"children": [
"hello"
]
}
]
}
]$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);output:
[
{
"$formkit": "group",
"label": "Group",
"value": {
"cities": [
"Hong Kong",
"Taiwan",
"China"
]
},
"children": [
{
"$el": "div",
"children": [
"$item"
],
"for": [
"item",
"key",
"$value.cities"
]
}
]
}
]