Skip to content

Instantly share code, notes, and snippets.

@ricardofiorani
Created March 13, 2014 14:34
Show Gist options
  • Save ricardofiorani/9529643 to your computer and use it in GitHub Desktop.
Save ricardofiorani/9529643 to your computer and use it in GitHub Desktop.
UserPasswordForm
<?php
namespace User\Form;
use Doctrine\ORM\EntityManager;
use DoctrineModule\Stdlib\Hydrator\DoctrineObject as DoctrineHydrator;
use User\Entity\User;
use Zend\Form\Form;
use Zend\InputFilter\InputFilterProviderInterface;
class UserPasswordForm extends Form implements InputFilterProviderInterface {
/**
* @var EntityManager
*/
protected $entityManager;
public function getEntityManager() {
return $this->entityManager;
}
public function setEntityManager(EntityManager $entityManager) {
$this->entityManager = $entityManager;
}
public function init() {
$this->setAttribute('class', 'form-horizontal');
$this->setAttribute('method', 'post');
$this->add(array(
'type' => 'hidden',
'name' => 'id',
'required' => true,
'filters' => array(
array('name' => 'Int'),
),
));
$this->add(array(
'type' => 'csrf',
'name' => 'csrf'
));
$this->add(array(
'name' => 'old_password',
'type' => 'password',
'attributes' => array(
'placeholder' => "Old Password",
'class' => 'form-control',
),
'options' => array(
'label' => "Old Password",
),
));
$this->add(array(
'name' => 'new_password',
'type' => 'password',
'attributes' => array(
'placeholder' => "New Password",
'class' => 'form-control',
),
'options' => array(
'label' => "Password",
),
));
$this->add(array(
'name' => 'new_password_confirm',
'type' => 'password',
'attributes' => array(
'placeholder' => "New Password (Confirm)",
'class' => 'form-control',
),
'options' => array(
'label' => "New Password (Confirm)",
),
));
}
public function getInputFilterSpecification() {
return array(
'old_password' => array(
'required' => true,
'filters' => array(
array('password' => 'Zend\Form\Element\Password'),
),
),
'new_password' => array(
'required' => true,
'filters' => array(
array('password' => 'Zend\Form\Element\Password'),
),
),
'new_password_confirm' => array(
'required' => true,
'filters' => array(
array('password' => 'Zend\Form\Element\Password'),
),
'validators' => array(
array(
'name' => 'Identitcal',
'options' => array(
'token' => 'new_password',
)
)
)
),
);
}
}
@danizord
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment