FosUserBundle registration validation new image field
I am using FOSUserBundle and i have problem with validation user entity.
In my user entity i have:
/**
* @AssertNotBlank()
* @AssertFile(
* maxSize="3M",
* mimeTypes={"image/png", "image/jpeg", "image/pjpeg"}
* )
* @VichUploadableField(mapping="profile_image", fileNameProperty="imageName")
*
* @var File $image
*/
protected $image;
What is good but this makes me damn not working WHILE REGISTRATION: "* @AssertNotBlank()" What is absolutly correct because i dont fill image while registration.
While user register, in controller is first condition: if ($process) { // what is actually if form is valid) and because there is no image its not valid...
My question is...
I have succesfully overriden RegistrationFormHandler file but now... HOW TO MODIFY IT? Or what to do .. maybe in some other file?
public function process($confirmation = false)
{
$user = $this->userManager->createUser();
$this->form->setData($user);
if ('POST' == $this->request->getMethod()) {
$this->form->bindRequest($this->request);
if ($this->form->isValid()) {
// do your custom logic here
return true;
}
}
return false;
}
I think something like... exception for registration validation for this field or something like that? IDK Thx!
use validation groups ...
validation groups make it possible to validate against different combinations of constraints.
In your case use a validation group ie 'registration' ( not containing the image/notblank constraints) for the signup form and another validation group ie 'profile' for your profile-edit form.
链接地址: http://www.djcxy.com/p/91682.html上一篇: FOSUserBundle覆盖不一致