Skip to content

Instantly share code, notes, and snippets.

@silentworks
Created December 10, 2014 16:27
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save silentworks/d80c1fb8794a0a0009de to your computer and use it in GitHub Desktop.
<?php
/**
* {$PROJECT_PATH}/src/App/Input/ContactForm.php
*/
namespace App\Input;
use Aura\Input\Form;
class ContactForm extends Form
{
public function init()
{
$states = array(
'AL' => 'Alabama',
'AK' => 'Alaska',
'AZ' => 'Arizona',
'AR' => 'Arkansas',
// ...
);
$this->setName('contact');
// set input fields
// hint the view layer to treat the first_name field as a text input,
// with size and maxlength attributes
$this->setField('first_name', 'text')
->setAttribs(array(
'id' => 'first_name',
'size' => 20,
'maxlength' => 20,
));
// hint the view layer to treat the state field as a select, with a
// particular set of options (the keys are the option values,
// and the values are the displayed text)
$this->setField('state', 'select')
->setAttribs(array(
'id' => 'state',
))
->setOptions($states);
$this->setField('message', 'textarea')
->setAttribs([
'id' => 'message',
'cols' => 40,
'rows' => 5,
]);
// etc.
// get filter object
$filter = $this->getFilter();
// set your filters.
$filter->addSoftRule('first_name', $filter::IS, 'string');
$filter->addSoftRule('first_name', $filter::IS, 'strlenMin', 4);
$filter->addSoftRule('state', $filter::IS, 'inKeys', array_keys($states));
$filter->addSoftRule('message', $filter::IS, 'string');
$filter->addSoftRule('message', $filter::IS, 'strlenMin', 6);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment