We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hello,
I have a FileType field in my form but I don't want to make it mandatory, unfortunately, "required" to false doesn't work.
Why?
The processing of this form is done in a Service and via a single save() method (create and update)
How to make this field not mandatory while keeping the constraints and verification in my Form class?
Thanks :)
Form class:
class MySuperForm implements FormFactoryInterface { public function buildForm(mixed $data = null, ?array $args = []) { $builder = (new FormBuilder('my_form', $data)) ->add('uploadedLogo', FileType::class, [ 'label' => 'Choisissez un fichier', 'constraints' => [ new FileConstraint\Extension([ 'extensions' => ['jpg', 'gif', 'png'], ]), new FileConstraint\MimeType([ 'mime_types' => ['image/jpeg', 'image/gif', 'image/png'], ]), ], 'required' => false, 'mapped' => false, ]); /// } }
Controller:
public function actionForm($request, $response, ?int $id): ResponseInterface { $datas = null; if($id != null){ $datas = $this->em->getRepository(MyEntity::class)->find($id); } $form = $this->formFactory->create(MySuperForm::class, $datas); $form->handleRequest(); // Envoi des données en POST if($form->isSubmitted() && $form->isValid()){ $data = [ 'form' => $form->getRequestData()['form_data'], 'uploadedFile' => $request->getUploadedFiles()['form_file'], ]; return $this->service->save($data, $datas); } }
Service:
public function save(array $data, ?MyEntity $myEntity): ResponseInterface { if (!empty($data['uploadedFile']['uploadedLogo'])) { /// traitment } }
The text was updated successfully, but these errors were encountered:
Hey @SelMaK-fr,
Sorry for the delay - I was busy with work and then had time off over the Christmas period.
I'll try and take a look at this in the coming days :)
Sorry, something went wrong.
No branches or pull requests
Hello,
I have a FileType field in my form but I don't want to make it mandatory, unfortunately, "required" to false doesn't work.
Why?
The processing of this form is done in a Service and via a single save() method (create and update)
How to make this field not mandatory while keeping the constraints and verification in my Form class?
Thanks :)
Form class:
Controller:
Service:
The text was updated successfully, but these errors were encountered: