Answer the question
In order to leave comments, you need to log in
How to access zfcuser zf2 forms?
Hello, I am working on a project on zf2 + doctrine. For authorization I use the zfcuser module, for separation of access rights (ACL) bjyauthorize.
I create a custom form to change the password:
<?php
namespace Application\Form;
use Zend\Form\Form;
class ClientpassForm extends Form{
public function __construct($em){
parent::__construct('security');
$this->add(array(
'name' => 'password-old',
'attributes' => array(
'type' => 'password',
'placeholder' => 'пароль',
'id' => 'key',
'class' => ''
),
'options' => array(
'label' => 'Введите ваш старый пароль',
'label_attributes' => array(
'class' => ''
),
),
));
$this->add(array(
'name' => 'password',
'attributes' => array(
'type' => 'password',
'placeholder' => 'новый пароль',
'id' => 'key',
'class' => ''
),
'options' => array(
'label' => 'Введите новый пароль',
'label_attribute' => array(
'class' => ''
),
),
));
$this->add(array(
'name' => 'password-confirm',
'attributes' => array(
'type' => 'password',
'placeholder' => 'новый пароль',
'id' => 'key',
'class' => ''
),
'options' => array(
'label' => 'Повторите новый пароль',
'label_attributes' => array(
'class' => ''
),
),
));
}
}
<?php
namespace Application\Form;
use Zend\InputFilter\Factory as InputFactory;
use Zend\InputFilter\InputFilter;
class ClientpassFilter extends InputFilter{
public function __construct($sm){
$this->add(array(
'name' => 'password',
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 4,
'max' => 100,
),
),
),
));
$this->add(array(
'name' => 'password-old',
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 4,
'max' => 100,
),
),
),
));
$this->add(array(
'name' => 'password-confirm',
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 4,
'max' => 100,
),
),
array(
'name' => 'Identical',
'options' => array(
'token' => 'password',
'messages' => array(
\Zend\Validator\Identical::NOT_SAME => 'Введенные пароли не совпадают'
),
),
),
),
));
}
}
public function securityAction(){
$this->getServiceLocator()->get('Zend\View\Renderer\PhpRenderer')->headTitle('Изменение данных пользователя');
$em = $this->getEntityManager();
$form = new \Application\Form\ClientpassForm($em);
return new ViewModel(array(
'form' => $form,
));
}
<?=$this->form()->openTag($form);?>
<?=$this->formRow($form->get('password-old'));?>
<br/>
<?=$this->formRow($form->get('password'));?>
<br/>
<?=$this->formRow($form->get('password-confirm'));?>
<br/>
<button type="submit">Сохранить</button>
<?=$this->form()->closeTag();?>
if ($request->isPost())
return $this->forward()->dispatch('zfcuser', array('action' => 'authenticate'));
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question