dev-master
9999999-dev https://github.com/FranzWegener/QuantumFormsQuantumForms is a customizable FormBuilder that uses the same validators in frontend and backend.
MIT
The Requires
- php >=5.3.0
by Franz Wegener
forms form-builder
Wallogit.com
2017 © Pedro Peláez
QuantumForms is a customizable FormBuilder that uses the same validators in frontend and backend.
QuantumForms is an easily customizable FormBuilder that uses the same validators in frontend and backend., (*2)
Installing QuantumForms is incredibly easy with composer, (*3)
composer require franzwegener/quantumforms
Alternatively, if your project doesn't use composer (QuantumForms doesn't have any dependencies, so composer isn't required!), you can simply include and register the autoloader., (*4)
require_once $quantumFormsRootPath.'/Autoloader.php'; $loader = new Autoloader(); $loader->register();
1). Instantiate your form, (*5)
$form = new Form('GET', '/desired/form/action.php', new Alert());
2). Define your form elements, and add them to your form. This assumes you've bound your form to the $form variable., (*6)
$ageElement = new TextInput('age');
$ageElement->setValidators([new Integer()]);
$form->addElement($ageElement);
$nameElement = new TextInput('name');
$nameElement->setValidators([new Alphanumeric()]);
$nameElement->setAttributes(['class' => 'form-control', 'id' =>'the-name-field']);
$nameElement->setHtmlBefore('
');
$nameElement->setHtmlAfter('Some text, (*7)
');
$form->addElement($nameElement);
$submitElement = new Submit('submit');
$form->addElement($submitElement);
3). Inject the form-object into your view, (*8)
<html>
<head>
<?= $form->renderJavascript(); ?>
</head>
<body>
<?= $form->renderHtml(); ?>
</body>
</html>
Extending QuantumForms allows you to use additional elements to your form., (*9)
1). Add file with new FormElement name to the /src/FormElements directory, e.g. src/FormElements/Example, (*10)
An example extention could look like this:, (*11)
namespace QuantumForms\FormElements;
/**
* Example FormElement
*/
class Example extends AbstractFormElement implements \Quantumforms\FormElementInterface
{
/**
* (non-PHPdoc)
* @see \QuantumForms\FormElements\AbstractFormElement::render()
*/
public function render()
{
$attributes = $this->getAttributesString();
return $this->htmlBefore.'<example '.$attributes.'/>'.$this->htmlAfter;
}
}
Make sure you add your element test in the tests directory, /tests/FormElements/Example.php., (*12)
If you would like to contribute your element back to the QuantumForms project, consider opening a pull request with your changes., (*13)
Add file with JsErrorNotifier name to the /src/JsErrorNotifiers directory, e.g. src/JsErrorNotifiers/Example, (*14)
namespace QuantumForms\JsErrorNotifiers;
/**
* Example JsErrorNotifier
*/
class Example implements \QuantumForms\JsErrorNotifierInterface
{
public function getJsErrorNotifier()
{
return 'function (elementName, validatorName){
//do something
}';
}
}
Add a test for your JsErrorNotifier to /tests/JsErrorNotifiers/Example.php, (*15)
Add file with validator name to the /src/Validators directory, e.g. src/Validators/Example, (*16)
namespace QuantumForms\Validators;
use QuantumForms\Validator;
use QuantumForms\ValidatorInterface;
/**
* Example Validator
*/
class Example extends AbstractValidator implements ValidatorInterface
{
/**
* @return bool
*/
public function validate($input)
{
$bool = some_validation($input);
return $bool;
}
/**
* @return string
*/
public function getJavascriptValidator()
{
return 'function (input) {
bool = some_validation(input);
return bool;
}';
}
}
Add a test for your Validator to /tests/Validators/Example.php, (*17)
This project doesn't come with any specific support plan, but I absolutely love helping out where I can. If you encounter any trouble with it at all, please don't hesitate to let me know. Just open an issue and I'll do what I can., (*18)
QuantumForms is a customizable FormBuilder that uses the same validators in frontend and backend.
MIT
forms form-builder