PHP WTForms library inspired by Python WTForms module
There are two ways to get WTForms-PHP, i.e. by composer install or download the package manually.
You can run the following terminal command in the root directory of your project:
composer install wtforms\wtforms
or add the the following lines to your composer.json file as a requirement:
wtforms\wtforms: 1.0
You can download the latest version of the project here
If your using composer with autoloading, you can simple use the WTForms
namespace to load specific classes or modules from the WTForms-PHP library. For instance:
use WTForms\Form;
use WTForms\Fields\StringField;
Otherwise, you have to manually include them by doing the following:
require_once 'path/to/wtforms-php/src/Form.php';
require_once 'path/to/wtforms-php/src/fields/StringField.php';
The example below is used to create form object with a list of form input fields.
class AddressForm extends Form{
function setUp(){
$this->_fields = [
"street" => (new Fields\StringField("Street")),
"town" => (new Fields\StringField("Town/District"))->required(),
"parish" => (new Fields\StringField("Parish"))->required(),
"country" => (new Fields\StringField("Country"))->required(),
]
}
}