Note that there are some explanatory texts on larger screens.

plurals
  1. POSimple recovery password form
    primarykey
    data
    text
    <p>again, im trying a simple form for recovery forgot user password.</p> <p>The form only contains a email input. The form handler, receive the email, search the user, restore your password and send a email with the new password. Is important says that user not is authenticated.</p> <p>So, i need create a custom constraint that check if the email exists in the db. I have an method of a own service that do it. So, i need bind the method with the constraint.</p> <p>The custom validation class is:</p> <pre><code>class ExistEmailValidator extends ConstraintValidator { protected $userService; public function setUserService($userService) { echo "Setter..."; var_dump($userService); die(); $this-&gt;userService = $userService; } public function validate($value, Constraint $constraint) { if($this-&gt;userService-&gt;existUserEmail($value) == false){ $this-&gt;context-&gt;addViolation($constraint-&gt;message, array('%string%' =&gt; $value)); } } } </code></pre> <p>I inject the service from services.yml:</p> <pre><code> validator.unique.ExistEmailValidator: class: AppsManantiales\CommonBundle\Validator\Constraints\ExistEmailValidator tags: - {name: validator.constraint_validator, alias: user_email_validator} calls: - [setUserService, ["userservice"]] </code></pre> <p>The problem is taht, never inject the service, because Symfony says:</p> <blockquote> <p>Error: Call to a member function existUserEmail() on a non-object</p> </blockquote> <p>Note: the user service id is: "userservice".</p> <pre><code>php app/console container:debug | grep UserService userservice container AppsManantiales\CommonBundle\Services\UserService </code></pre> <p>Any ideas ?</p> <p><strong>UPDATE 1</strong></p> <p>My constraint class is:</p> <pre><code>class ExistEmail extends Constraint{ public $message = 'El e-mail "%string%" no pertenece a ningun usuario del sistema.'; public function validatedBy() { return get_class($this).'Validator'; } } </code></pre> <p>And the form definition is:</p> <pre><code>public function buildForm(FormBuilderInterface $builder, array $options) { $builder-&gt;add('anUserEmail', 'email', array( 'constraints' =&gt; array( new ExistEmail() ) )); } </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. 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