Answer the question
In order to leave comments, you need to log in
How to disassemble form_widget for parts?
Tell me how to customize form_widget? how to make normal inputs from form_widget so that you can work with each one separately?
controller:
public function register(Request $request, UserPasswordEncoderInterface $passwordEncoder, GuardAuthenticatorHandler $guardHandler, LoginFormAuthenticator $formAuthenticator)
{
$form = $this->createForm(UserRegistrationFormType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
/** @var User $user */
$user = $form->getData();
$user->setPassword($passwordEncoder->encodePassword($user, $user->getPassword()));
$em = $this->getDoctrine()->getManager();
$em->persist($user);
$em->flush();
}
return $this->render('security/register.html.twig', [
'registrationForm' => $form->createView(),
]);
{{ form_start(registrationForm) }}
{{ form_widget(registrationForm, {'attr': {'class': 'uk-margin-large'}}) }}
<button class="btn btn-lg btn-primary btn-block" type="submit">
Register
</button>
{{ form_end(registrationForm) }}
<form action="..">
<input ...
<button ...
</form>
Answer the question
In order to leave comments, you need to log in
how to customize forms
The widget consists of a form_row() where each row is responsible for one input. To override the rendering of one row, you need to find the alias of this piece of the template in the vendor of the form component and create a separate template just for this input (or for the widget). Symfonycasts has an explainer video
{{ form_start(registrationForm) }}
<div class="uk-margin">
{{ form_label(registrationForm.email, 'Эл. почта', {'label_attr': {'class': 'uk-form-label'}}) }}
{{ form_widget(registrationForm.email, {'attr': {'class': 'uk-input'}}) }}
</div>
<div class="uk-margin">
{{ form_label(registrationForm.password, 'Пароль', {'label_attr': {'class': 'uk-form-label'}}) }}
{{ form_widget(registrationForm.password, {'attr': {'class': 'uk-input'}}) }}
</div>
<div class="uk-margin" style="display:flex;justify-content:center">
<button class="uk-button uk-button-primary" type="submit">
Зарегистрироваться
</button>
</div>
{{ form_end(registrationForm) }}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question