2017 © Pedro Peláez
 

library php-wtforms

A PHP rewrite of the fantastic Python library WTForms

image

deathnerd/php-wtforms

A PHP rewrite of the fantastic Python library WTForms

  • Tuesday, September 13, 2016
  • by Deathnerd
  • Repository
  • 2 Watchers
  • 3 Stars
  • 242 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 4 Open issues
  • 6 Versions
  • 1 % Grown

The README.md

Build Status, (*1)

codecov, (*2)

php-wtforms

A PHP rewrite of the fantastic Python library WTForms., (*3)

I do not take credit for the idea behind WTForms or anything related to its original implementation. I just bastardized it and ported it to PHP., (*4)

Install

Add the following line to the require portion of your composer.json, (*5)

"deathnerd/php-wtforms":"0.5.2"

or if you're feeling froggy, pull in the cutting edge master release, (*6)

"deathnerd/php-wtforms":"dev-master"

or run the following command from your favorite terminal for the stable version, (*7)

composer require deathnerd/php-wtforms:0.5.2

or for the bleeding edge dev release, (*8)

composer require deathnerd/php-wtforms:dev-master

Note: The dev-master version is not guaranteed to be stable., (*9)

Quick Start

To create a simple login-form it's as simple as this:, (*10)

LogInForm.php

username = new StringField(["validators"=>[
            new InputRequired("You must provide a username"),
            new Length("Usernames must be between %(min)d and %(max)d characters long", ["min"=>3, "max"=>10]),
            new NotContains("Usernames may not contain the following characters: ;-/@", ["invalid_members"=>[";","-","/","@"]])
        ]]);
        $this->password = new PasswordField(["validators"=>[
            new InputRequired("Can't log in without a password!"),
            new Length("Passwords must be at least %(min)d characters in length", ["min"=>5])
        ]]);
        $this->submit = new SubmitField(["label"=>"Submit"]);
    }
}
```

### NotContains.php

```php
 []])
    {
        assert(!empty($options['invalid_members']), "Doesn't make sense to not have any invalid members");
        $this->invalid_members = $options['invalid_members'];
        $this->message = $message;
    }

    /**
     * @param Form   $form
     * @param Field  $field
     * @param string $message
     *
     * @return mixed True if the field passed validation, a Validation Error if otherwise
     * @throws ValidationError
     */
    public function __invoke(Form $form, Field $field, $message = "")
    {
        if (strlen($field->data) != strlen(str_replace($this->invalid_members, "", $field->data))) {
            if ($message == "") {
                if ($this->message == "") {
                    $message = "Invalid Input.";
                } else {
                    $message = $this->message;
                }
            }
            throw new ValidationError($message);
        }

        return true;
    }
}
```

### login.php

```php
 $_POST]);

if ($_POST) {
    if ($form->validate()) {
        // do stuff to log in and authenticate the user
    }
}
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>LogIn Form</title>
</head>
<body>
errors) { ?>
    <ul class="errors">
        <?php
        foreach ($form->errors as $field_name => $errors) {
            foreach ($errors as $field_error) { ?>
                <li><?= $field_name ?> - <?= $field_error ?></li>
                <?php
            }
        }
        ?>
    </ul>



= $form->username->label ?> = $form->username ?> = $form->password->label ?> = $form->password ?> = $form->submit ?>
</body> </html>

And that's that. More in-depth examples and actual documentation are coming in the future. For now, look in the tests directory for ideas on how to do things, (*11)

The Versions

13/09 2016

dev-master

9999999-dev

A PHP rewrite of the fantastic Python library WTForms

  Sources   Download

GPL-2.0

The Requires

 

The Development Requires

by Wes Gilleland

18/08 2016

0.5.2

0.5.2.0

A PHP rewrite of the fantastic Python library WTForms

  Sources   Download

GPL-2.0

The Requires

 

The Development Requires

by Wes Gilleland

08/07 2016

0.5.1

0.5.1.0

A PHP rewrite of the fantastic Python library WTForms

  Sources   Download

GPL-2.0

The Requires

 

The Development Requires

by Wes Gilleland

04/07 2016

0.5.0

0.5.0.0

A PHP rewrite of the fantastic Python library WTForms

  Sources   Download

GPL-2.0

The Requires

 

The Development Requires

by Wes Gilleland

10/06 2016

dev-docs

dev-docs

A PHP rewrite of the fantastic Python library WTForms

  Sources   Download

GPL-2.0

The Requires

 

The Development Requires

by Wes Gilleland

30/05 2016

dev-dev

dev-dev

A PHP rewrite of the fantastic Python library WTForms

  Sources   Download

GPL-2.0

The Requires

  • php >=5.5

 

The Development Requires

by Wes Gilleland