Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
100.00% |
1 / 1 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
23 / 23 |
AclUser\Form\BasicProfileForm | |
100.00% |
1 / 1 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
23 / 23 |
__construct | |
100.00% |
1 / 1 |
1 | |
100.00% |
5 / 5 |
|||
addElements | |
100.00% |
1 / 1 |
1 | |
100.00% |
9 / 9 |
|||
addInputFilter | |
100.00% |
1 / 1 |
1 | |
100.00% |
9 / 9 |
<?php | |
/** | |
* Class RegistrationForm Creates the login form | |
* | |
* @package AclUser\Form | |
* @author Nigel Hurnell | |
* @version v 1.0.0 | |
* @license BSD | |
* @copyright Copyright (c) 2017, Nigel Hurnell | |
*/ | |
namespace AclUser\Form; | |
use Zend\Form\Form; | |
use Zend\InputFilter\InputFilter; | |
/** | |
* This form is used to create a new user. | |
* | |
* @package AclUser\Form | |
* @author Nigel Hurnell | |
* @version v 1.0.0 | |
* @license BSD | |
* @copyright Copyright (c) 2017, Nigel Hurnell | |
*/ | |
class BasicProfileForm extends Form | |
{ | |
/** | |
* Constructor. | |
* | |
*/ | |
public function __construct() | |
{ | |
// Define form name | |
parent::__construct('basic-profile-form'); | |
// Set POST method for this form | |
$this->setAttribute('method', 'post'); | |
$this->addElements(); | |
$this->addInputFilter(); | |
} | |
/** | |
* This method adds elements to form (input fields and submit button). | |
*/ | |
protected function addElements() | |
{ | |
// Add "new_password" field | |
$this->add([ | |
'type' => 'text', | |
'name' => 'full_name', | |
'options' => [ | |
'label' => 'Full Name', | |
], | |
]); | |
// Add "email" field | |
$this->add([ | |
'type' => 'email', | |
'name' => 'email', | |
'options' => [ | |
'label' => 'E-mail', | |
], | |
]); | |
// Add the CSRF field | |
$this->add([ | |
'type' => 'csrf', | |
'name' => 'csrf', | |
'options' => [ | |
'csrf_options' => [ | |
'timeout' => 600 | |
] | |
], | |
]); | |
// Add the Submit button | |
$this->add([ | |
'type' => 'submit', | |
'name' => 'submit', | |
'attributes' => [ | |
'value' => 'Update', | |
'id' => 'submit-update-profile', | |
'class' => 'btn btn-lg btn-primary btn-block' | |
], | |
]); | |
} | |
/** | |
* This method creates input filter (used for form filtering/validation). | |
*/ | |
private function addInputFilter() | |
{ | |
// Create main input filter | |
$inputFilter = new InputFilter(); | |
$this->setInputFilter($inputFilter); | |
$inputFilter->add([ | |
'name' => 'full_name', | |
'required' => true, | |
'filters' => [ | |
], | |
'validators' => [ | |
[ | |
'name' => 'StringLength', | |
'options' => [ | |
'min' => 1, | |
'max' => 64 | |
], | |
], | |
], | |
]); | |
// Add input for "email" field | |
$inputFilter->add([ | |
'name' => 'email', | |
'required' => true, | |
'filters' => [ | |
['name' => 'StringTrim'], | |
], | |
'validators' => [ | |
[ | |
'name' => 'EmailAddress', | |
'options' => [ | |
'allow' => \Zend\Validator\Hostname::ALLOW_DNS, | |
'useMxCheck' => false, | |
], | |
], | |
], | |
]); | |
} | |
} |