This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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