Sirius Input
Sirius Input is a framework agnostic PHP library for handling data coming to your application. It is suitable for forms, APIs (RESTful or not), CLI apps
Elevator pitch
$form = new \Sirius\Input\InputFilter();
$form->add('name', [
'type' => 'text',
'label' => 'Name',
'rules' => ['required']
]);
$form->add('email', [
'type' => 'text',
'label' => 'Email',
'rules' => ['required', 'email']
]);
$form->add('message', [
'type' => 'textarea',
'label' => 'Message',
'hint' => 'Please write in detail the problem you are facing',
'rules' => ['required']
]);
$form->add('recaptcha', [
'type' => 'recaptch',
'label' => 'Are you human or are you dancer?'
]);
$form->add('submit', [
'type' => 'submit',
'label' => 'Send request'
]);
$form->populate($_POST);
if ($form->isValid()) {
// send message to admin, persist to database etc
} else {
$view->set('errors', $form->getErrors());
}
The Sirius\Input depends on:
- Sirius\Validation for validating the data,
- Sirius\Filtration for filtering/sanitizing data and
- Sirius\Upload for handling file uploads
The Sirius\Input library doesn't render the forms for a few reasons:
- Single Responsibility Principle
- the library can be used for handling data coming from APIs. In this case a more appropriate render destination would be the API documentation
- different frameworks implement different ways to render things. Think about how to handle CSS/JS dependencies.
But because rendering forms is such a big part in any project we created Sirius\FormsRenderer as a starting base for such task.