Skip to content

PHP WTForms library inspired by Python WTForms module

Notifications You must be signed in to change notification settings

anzeljg/wtforms-php

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wtforms-php

PHP WTForms library inspired by Python WTForms module

Installing WTForms-PHP

There are two ways to get WTForms-PHP, i.e. by composer install or download the package manually.

Get WTForms-PHP via composer

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

Get WTForms-PHP via download

You can download the latest version of the project here

Using WTForms-PHP in your project

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';

Create a WTForm Object

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(),
        ]
    }
}

About

PHP WTForms library inspired by Python WTForms module

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%