Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Since Symfony 2.3 you can easily use <a href="http://symfony.com/doc/current/reference/constraints/UserPassword.html" rel="noreferrer"><code>UserPassword</code></a> validation constraint.</p> <p><kbd>Acme\UserBundle\Form\Model\ChangePassword.php</kbd> </p> <pre><code>namespace Acme\UserBundle\Form\Model; use Symfony\Component\Security\Core\Validator\Constraints as SecurityAssert; use Symfony\Component\Validator\Constraints as Assert; class ChangePassword { /** * @SecurityAssert\UserPassword( * message = "Wrong value for your current password" * ) */ protected $oldPassword; /** * @Assert\Length( * min = 6, * minMessage = "Password should by at least 6 chars long" * ) */ protected $newPassword; } </code></pre> <p><kbd>Acme\UserBundle\Form\ChangePasswordType.php</kbd> </p> <pre><code>namespace Acme\UserBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolverInterface; class ChangePasswordType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder-&gt;add('oldPassword', 'password'); $builder-&gt;add('newPassword', 'repeated', array( 'type' =&gt; 'password', 'invalid_message' =&gt; 'The password fields must match.', 'required' =&gt; true, 'first_options' =&gt; array('label' =&gt; 'Password'), 'second_options' =&gt; array('label' =&gt; 'Repeat Password'), )); } public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver-&gt;setDefaults(array( 'data_class' =&gt; 'Acme\UserBundle\Form\Model\ChangePassword', )); } public function getName() { return 'change_passwd'; } } </code></pre> <p><kbd>Acme\UserBundle\Controller\DemoController.php</kbd> </p> <pre><code>namespace Acme\UserBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; use Acme\UserBundle\Form\ChangePasswordType; use Acme\UserBundle\Form\Model\ChangePassword; class DemoController extends Controller { public function changePasswdAction(Request $request) { $changePasswordModel = new ChangePassword(); $form = $this-&gt;createForm(new ChangePasswordType(), $changePasswordModel); $form-&gt;handleRequest($request); if ($form-&gt;isSubmitted() &amp;&amp; $form-&gt;isValid()) { // perform some action, // such as encoding with MessageDigestPasswordEncoder and persist return $this-&gt;redirect($this-&gt;generateUrl('change_passwd_success')); } return $this-&gt;render('AcmeUserBundle:Demo:changePasswd.html.twig', array( 'form' =&gt; $form-&gt;createView(), )); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload