https://github.com/grassator/duckform
Use regular HTML5 markup for dealing with forms in PHP
https://github.com/grassator/duckform
Last synced: 10 months ago
JSON representation
Use regular HTML5 markup for dealing with forms in PHP
- Host: GitHub
- URL: https://github.com/grassator/duckform
- Owner: grassator
- License: mit
- Created: 2013-12-03T19:26:54.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2014-01-14T16:06:40.000Z (almost 12 years ago)
- Last Synced: 2023-04-09T14:49:33.727Z (almost 3 years ago)
- Language: PHP
- Size: 156 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-MIT
Awesome Lists containing this project
README
# Duck Form
Provides a way to use regular HTML5 form markup to populate forms with values and validate them on server side with PHP. It's also quite fast.
## Why "Duck"?
Ducks are cool!
## Usage
Simple usage looks like this:
```php
require 'DuckForm.php';
$form = DuckForm::fromFile("file_with_form_markup.html");
// Custom validator
$this->form->addFieldValidator('country', function($value, $fields, $form){
if(count($value) > 2) {
return "There should be more than 2 countries selected.";
}
return false;
})
if($_SERVER['REQUEST_METHOD'] === 'POST') {
$form->bind($_REQUEST);
if($form->validate()) {
// Form processing should go here
// redirecting user to a thank you page
header('Location: /thankyou.html');
exit;
}
}
echo $form;
```
It will render errors if necessary and will re-fill submitted form data.
## Requirements
PHP 5 with [DOM extension](http://www.php.net/manual/en/book.dom.php), which is bundled by default.
## Configuration
You can customize html classes for generated errors.
```php
$form->errorClass = 'my-error-class';
$form->errorListClass = 'my-error-list-class';
```
## Known Issues / Missing Features
* No file upload support
* Lack of validators except for required and email
## Licensing
Licensed under permissive [MIT-style license](https://github.com/grassator/duckform/blob/master/LICENSE-MIT).