Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/akrabat/rka-slim-zendform
https://github.com/akrabat/rka-slim-zendform
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/akrabat/rka-slim-zendform
- Owner: akrabat
- License: bsd-3-clause
- Created: 2015-05-03T13:41:32.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2019-04-25T13:50:06.000Z (almost 6 years ago)
- Last Synced: 2024-10-04T11:30:52.715Z (4 months ago)
- Language: PHP
- Size: 6.84 KB
- Stars: 1
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Zend\Form integration with Slim 3
This service provider integrates Zend\Form into a Slim 3 application.
## Usage
1. `composer require slim/twig-view`
2. `composer require akrabat/rka-slim-zendform`
3. Register Twig-View as per the [README](https://github.com/slimphp/Twig-View/)
3. Register the `FormProvider` in index.php:$app->getContainer()->register(new RKA\Form\FormProvider);
4. Create a form:
add([
'name' => 'email',
'options' => [
'label' => 'Email address',
],
'attributes' => [
'id' => 'email',
'class' => 'form-control',
'required' => 'required',
],
]);$this->add([
'name' => 'submit',
'type' => 'button',
'options' => [
'label' => 'Go!',
],
'attributes' => [
'class' => 'btn btn-default',
],
]);
}public function getInputFilterSpecification()
{
return [
'email' => [
'required' => true,
'filters' => [
['name' => 'StringTrim'],
['name' => 'StripTags'],
],
'validators' => [
['name' => 'EmailAddress'],
],
],
];
}
}5. Example action:
$app->map(['GET', 'POST'], '/', function ($request, $response) {
$sm = $this['serviceManager'];
$formElementManager = $sm->get('FormElementManager');
$form = $formElementManager->get("RKA\ExampleForm");if ($request->isPost()) {
$data = $request->post();
$form->setData($data);
$isValid = $form->isValid();
if ($form->isValid()) {
echo "Success!";
exit;
}
}$this['view']->render($response, 'home.twig', array(
'form' => $form
));
return $response;
});