Bonjour,
mon controller est des plus simples et basique, mais la condition if ($form->isSubmitted() && $form->isValid()) ne veut pas s'éxécuter !
Alors bien sûr , à mon petit niveau je me dis : soit ce n'est pas valide, soit ce n'est pas soumis.
Mais je n'ai aucun message d'erreur.
Alors je fait naïvement unEt j'obtient un bonjour. Victoire: je sais maintenant que mon formulaire n'est pas valide, mais pourquoi ?
Code php : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 if ($form->isSubmitted()) { dd('bonjour'); }
Du coup je ne sais pas ce qui cloche, surtout je ne sais pas comment tester pour savoir ce qui cloche !
Je rentre un nom, prenom, email mot de passe et une fois soumis tout ça, ....... je reviens au formulaire d'enregistrement au lieu du formulaire de connection !
mon registerController ne vous choque pas ( j'espère ):
Code php : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 class RegistrationController extends AbstractController { /** * @Route("/register", name="app_register") */ public function register(Request $request, UserPasswordHasherInterface $userPasswordHasherInterface): Response { $user = new User(); $form = $this->createForm(RegistrationFormType::class, $user); $form->add('register', SubmitType::class, [ 'label' => 'enregistrer' ]); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { // encode the plain password $user->setPassword( $userPasswordHasherInterface->hashPassword( $user, $form->get('plainPassword')->getData() ) ); $entityManager = $this->getDoctrine()->getManager(); $entityManager->persist($user); $entityManager->flush(); // do anything else you need here, like send an email return $this->redirectToRoute('app_login'); } return $this->render('registration/register.html.twig', [ 'registrationForm' => $form->createView(), ]); } }
J'imagine que mon twig non plus:
Code html : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 {% extends 'layouts/base.html.twig' %} {% block title %}Register{% endblock %} {% block content %} <h1 class="text-capitalize">Enregistrement</h1> <form> <div class="form-group"> <label for="email">{{form_label(registrationForm.email, 'votre Email')}}</label> {{ form_widget(registrationForm.email, {'attr': {'class': 'form-control', 'id': 'email'}}) }} </div> <div class="form-group"> <label for="firstName">{{form_label(registrationForm.firstName, 'votre prénom')}}</label> {{ form_widget(registrationForm.firstName, {'attr': {'class': 'form-control', 'id': 'firstName'}}) }} </div> <div class="form-group"> <label for="lastName">{{form_label(registrationForm.email, 'votre nom')}}</label> {{ form_widget(registrationForm.lastName, {'attr': {'class': 'form-control', 'id': 'lastName'}}) }} </div> <div class="form-group"> {{ form_widget(registrationForm.plainPassword) }} </div> <div class="form-group form-check"> <label class="form-check-label" for="agree">{{ form_label(registrationForm.agreeTerms) }}</label> {{ form_widget(registrationForm.agreeTerms, {'attr': {'class': 'form-check-input', 'id': 'agree'}}) }} </div> {{ form_widget(registrationForm.register) }} {# <button type="submit" class="btn btn-primary">Submit</button> #} </form> {% endblock %}
et pour terminer, mon user ( que j'imagine correct aussi ):
Code php : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163 <?php namespace App\Entity; use App\Repository\UserRepository; use Doctrine\ORM\Mapping as ORM; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; use Symfony\Component\Security\Core\User\UserInterface; /** * @ORM\Entity(repositoryClass=UserRepository::class) * @UniqueEntity(fields={"email"}, message="There is already an account with this email") */ class User implements UserInterface, PasswordAuthenticatedUserInterface { /** * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") */ private $id; /** * @ORM\Column(type="string", length=180, unique=true) */ private $email; /** * @ORM\Column(type="json") */ private $roles = []; /** * @var string The hashed password * @ORM\Column(type="string") */ private $password; /** * @ORM\Column(type="string", length=255, nullable=true) */ private $firstName; /** * @ORM\Column(type="string", length=255, nullable=true) */ private $lastName; public function getId(): ?int { return $this->id; } public function getEmail(): ?string { return $this->email; } public function setEmail(string $email): self { $this->email = $email; return $this; } /** * A visual identifier that represents this user. * * @see UserInterface */ public function getUserIdentifier(): string { return (string) $this->email; } /** * @deprecated since Symfony 5.3, use getUserIdentifier instead */ public function getUsername(): string { return (string) $this->email; } /** * @see UserInterface */ public function getRoles(): array { $roles = $this->roles; // guarantee every user at least has ROLE_USER $roles[] = 'ROLE_USER'; return array_unique($roles); } public function setRoles(array $roles): self { $this->roles = $roles; return $this; } /** * @see PasswordAuthenticatedUserInterface */ public function getPassword(): string { return $this->password; } public function setPassword(string $password): self { $this->password = $password; return $this; } /** * Returning a salt is only needed, if you are not using a modern * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml. * * @see UserInterface */ public function getSalt(): ?string { return null; } /** * @see UserInterface */ public function eraseCredentials() { // If you store any temporary, sensitive data on the user, clear it here // $this->plainPassword = null; } public function getFirstName(): ?string { return $this->firstName; } public function setFirstName(?string $firstName): self { $this->firstName = $firstName; return $this; } public function getLastName(): ?string { return $this->lastName; } public function setLastName(?string $lastName): self { $this->lastName = $lastName; return $this; } }
Je me dis que ça cloche ailleurs ,car , ça marchait avant
Forcément , j'ai fait un changement qui gêne. Mais mon niveau ne me permet pas de savoir où chercher ...
Merci à vous,
Laurent.
Partager