gsouf / uform
Full featured form library
0.2.0
2020-03-22 20:26 UTC
Requires
- php: >=5.6.0
- twig/twig: ~1.15,>=1.15.1
Requires (Dev)
- couscous/couscous: ^1.5.2
- minime/annotations: ~2.0
- phpunit/phpunit: ^5.7.19
- squizlabs/php_codesniffer: ~2.5
This package is auto-updated.
Last update: 2024-11-23 06:37:14 UTC
README
UForm is a form validation/filtering/rendering library for PHP.
Usage
Quick start
use UForm\Builder; $form = Builder::init("action", "POST") ->columnGroup() ->column(3, 12) ->text("firstname", "Firstname")->required()->stringLength(2, 20) ->text("lastname", "Lastname")->required()->stringLength(2, 20) ->close() ->column(3, 12) ->panel('Login Information') ->text("login", "Login")->required()->stringLength(2, 20) ->password("password", "Password")->required()->stringLength(2, 20) ->close() ->close() ->close() ->getForm(); //If it's a post request we validate the form with the post data if ($_SERVER['REQUEST_METHOD'] == "POST") { $formContext = $form->validate($form->getInputFromGlobals()); if ($formContext->isValid()) { $filteredData = $formContext->getData(); // Do some logic with data // ... } } else { // Or else we just generate a context with empty values $formContext = $form->generateContext([]); } // We want to render some html for bootstrap 3 $formRenderer = new Bootstrap3Render(); $html = $formRenderer->render($formContext); echo $html;
The above example will result in:
Full documentation
The full documentation will available at gsouf.github.io/UForm once the project will be considered as stable