This package requires PHP>=7.1 and is available on Packagist:
composer require form-manager/form-manager
Create a field
FormManager is namespaced, but you only need to import a single class into your context:
useFormManager\FactoryasF;
Use the imported factory to create all form elements:
'name-field']);
//Add or remove attributes
$name->setAttribute('title', 'This is the name input');
$name->removeAttribute('class');
$name->setAttributes([
'required',
'readonly',
'tabindex' => 2,
'maxlength' => 50
]);
//Set the value
$name->setValue('MyName');
//Use magic properties to get/set/remove attributes
$name->class = 'name-field';
$name->required = false;
unset($name->readonly);
">
//Create an input type="text" element$name = F::text();
//Create the input with a label$name = F::text('Please, introduce your name');
//Or with extra attributes$name = F::text('Please, introduce your name', ['class' => 'name-field']);
//Add or remove attributes$name->setAttribute('title', 'This is the name input');
$name->removeAttribute('class');
$name->setAttributes([
'required',
'readonly',
'tabindex' => 2,
'maxlength' => 50
]);
//Set the value$name->setValue('MyName');
//Use magic properties to get/set/remove attributes$name->class = 'name-field';
$name->required = false;
unset($name->readonly);
List of all available inputs:
All HTML5 field types are supported:
F::checkbox($label, $attributes)
F::color($label, $attributes)
F::date($label, $attributes)
F::datetimeLocal($label, $attributes)
F::email($label, $attributes)
F::file($label, $attributes)
F::hidden($value, $attributes)
F::month($label, $attributes)
F::number($label, $attributes)
F::password($label, $attributes)
F::radio($label, $attributes)
F::range($label, $attributes)
F::search($label, $attributes)
F::select($label, $options, $attributes)
F::submit($label, $attributes)
F::tel($label, $attributes)
F::text($label, $attributes)
F::textarea($label, $attributes)
F::time($label, $attributes)
F::url($label, $attributes)
F::week($label, $attributes)
Note that all inputs accepts the same arguments except hidden and select.
Validation
This library uses internally symfony/validation to perform basic html5 validations and error reporting. HTML5 validation attributes like required, maxlength, minlength, pattern, etc are supported, in addition to intrinsic validations assigned to each input like email, url, date, etc.
$email = F::email();
$email->setValue('invalid-email');
//Validate the valueif ($email->isValid()) {
returntrue;
}
//Get errors$error = $email->getError();
//Print the first error messageecho$error;
//Iterate through all messagesforeach ($erroras$err) {
echo$err->getMessage();
}
//You can also customize/translate the error messages$email->setErrorMessages([
'email' => 'The email is not valid',
'required' => 'The email is required',
'maxlength' => 'The email is too long, it must have {{ limit }} characters or less',
]);
//And add more symfony validators$ip = F::text();
$ip->addConstraint(newConstraints\Ip());
But in version 6.1 there was no any erros, but select will look like (got only groups):
If such breaking chenge made intentionally there should be check and exception with hint how developer must adjust their code.
But really it is is bug on my mind. There was no any deprecation in Select interface, so breaking change should not be happened in stable versions (e.g. 6.*).
in case when Select::val($value) $value is not integer or string, eg bool :
Select::applyValues(array $value) will not apply old normalize method, array_flip() will raise warning
PHP 3. FormManager\\Fields\\Duplicable->add() /var/www/html/fmtest2/index.php:37
PHP 4. FormManager\\Fields\\Collection->add() /var/www/html/fmtest2/vendor/form-manager/form-manager/src/Fields/Duplicable.php:27
PHP Fatal error: Call to a member function addDuplicate() on a non-object in /var/www/html/fmtest2/index.php on line 41
I need to clear the current options with new options (differents). How can I do it?
There are some empty method like jQuery?
My example:
$form['states_id']->options([1 => 'aaaa']);
... very long process ...
$form['states_id']->options([2 => 'bbbb']);
After last step, $form['status_id'] has first and second assignment, but I need to clear first options without define again or other field redefinitions. Something like:
$form['states_id']->options([1 => 'aaaa']);
... very long process ...
$form['states_id']->empty()->options([2 => 'bbbb']);
------ ----------------------------------------------------------------------------------------------------------
Line ValidationError.php
------ ----------------------------------------------------------------------------------------------------------
43 Call to an undefined method Symfony\Component\Validator\ConstraintViolationListInterface::getIterator().
------ ----------------------------------------------------------------------------------------------------------
Added support for PSR-7. Now you can load the values with the new method loadFromPsr7():
$form->loadFromPsr7($serverRequestInstance);
Added support for fieldsets in forms. This fixes #56
$form = F::form()->fieldsets([
'fieldset-1' => [
'name' => F::text()->label('Name'),
'surname' => F::text()->label('Surname')
]
]);
//You can access to the fields in the same way:
echo $form['name'];
//But also get the fields grouped:
foreach ($form->fieldsets() as $fieldset) {
echo $fieldset;
}
The label and errorLabel of fields are always available but only will be printed if they have any content. This allows to configure the label and errorLabel in a more flexible way (#53). Example:
This Project is based on course CSC 3215. Learning about - Basic HTML & CSS, JSON, XML, Session & Cookies, CRUD Operations in Php using MySQL and Create MVC (Model–View–Controller) from scratch. Just learning about web technologies, Not focusing on UI (Bootstrap or other 3rd-Party UI libraries or frameworks).
html-sanitizer is a library aiming at handling, cleaning and sanitizing HTML sent by external users (who you cannot trust), allowing you to store it and display it safely. It has sensible defaults to provide a great developer experience while still being entierely configurable.
Formcreator is a plugin which allow creation of custom forms of easy access. At the same time, the plugin allow the creation of one or more tickets when the form is filled.