How to customize FOSUserBundle forms - php

I have below problem with FOSUserBundle customization.
I was overwritten FOSUser register form, then I changed register_content from
{{ form_widget(form) }}
to:
<div class="col-md-6">
{{ form_label(form.firstname) }}
{{ form_errors(form.firstname) }}
{{ form_widget(form.firstname) }}
{{ form_label(form.lastname) }}
{{ form_errors(form.lastname) }}
{{ form_widget(form.lastname) }}
</div>
<div class="col-md-6">
{{ form_label(form.email) }}
{{ form_errors(form.email) }}
{{ form_widget(form.email) }}
{{ form_label(form.plainPassword) }}
{{ form_errors(form.plainPassword) }}
{{ form_widget(form.plainPassword) }}
{{ form_label(form.plainPassword.second) }}
{{ form_errors(form.plainPassword.second) }}
{{ form_widget(form.plainPassword.second) }}
</div>
But, when I was went to the browser, I got it:
bad form render
The form renders incorrectly. How I can repair this?

try with this
{{ form_label(form.plainPassword.first) }}
{{ form_errors(form.plainPassword.first) }}
{{ form_widget(form.plainPassword.first) }}
{{ form_label(form.plainPassword.second) }}
{{ form_errors(form.plainPassword.second) }}
{{ form_widget(form.plainPassword.second) }}

Related

Form errors not appear in a custom form theme with EasyAdmin3

I overrided my form in EasyAdmin to organize differently my input so I did like this :
In my Crud :
public function configureCrud(Crud $crud): Crud
{
return $crud
->setPageTitle(Crud::PAGE_INDEX, 'admin.menu.infos')
->setFormThemes(['bundles/EasyAdminBundle/crud/company/edit.html.twig'])
;
}
And in my Twig :
{% extends '#EasyAdmin/crud/form_theme.html.twig' %}
{% use '#EasyAdmin/symfony-form-themes/bootstrap_5_layout.html.twig' %}
{% block form %}
{{ form_start(form) }}
<div class="row">
{{ form_row(form.logo) }}
{{ form_row(form.phone) }}
{{ form_row(form.catchphrase) }}
</div>
<div class="row">
{{ form_row(form.businessName) }}
{{ form_row(form.email) }}
{{ form_row(form.website) }}
</div>
<div class="row">
{{ form_row(form.companyName) }}
{{ form_row(form.address) }}
{{ form_row(form.linkedin) }}
</div>
<div class="row">
{{ form_row(form.siren) }}
{{ form_row(form.zipcode) }}
{{ form_row(form.facebook) }}
</div>
<div class="row">
{{ form_row(form.legalForm) }}
{{ form_row(form.city) }}
{{ form_row(form.twitter) }}
</div>
<div class="row">
{{ form_row(form.description) }}
</div>
{{ form_end(form) }}
{% endblock %}
The form is like I wanted and when I submit, it's work but the problem is when I make an error. For example if I valid with an empty value, then instead of getting my form_errors, I've got a 500.
I've tried different things but none of them worked :
block errors :
{{ form_start(form) }}
{% block form_errors %}
{{ parent() }}
{% endblock %}
individual error :
{{ form_errors(form.businessName) }}
Any idea ?

How to render individual fields from DateTimeType?

How to render individual fields from DateTimeType?
{{ form_widget(form.datetime.year) }}
{{ form_widget(form.datetime.month) }}
{{ form_widget(form.datetime.day) }}
{{ form_widget(form.datetime.hour) }}
{{ form_widget(form.datetime.minute) }}
{{ form_widget(form.datetime.second) }}
Didn't work.
Or how can I have it in separate fields in the view, but in the database and Entity in one?

Issue with resizing fields of form under symfony 3

I have a problem with resizing the fields I've generated with symfony, my fields take the whole width of the page. Here is my code:
Controller :
$user= new User();
$form=$this->CreateFormBuilder($user)
->add("firstName",TextType::class)
->add("lastName",TextType::class)
->add("login",TextType::class)
->add("password",PasswordType::class)
->add("tel",TextType::class)
->add("email",TextType::class)
->add("address",TextType::class)
->add("send",SubmitType::class)
-> getForm();
$form->handleRequest($req);
if($form->isValid())
{
$em=$this->getDoctrine()->getManager();
$em->persist($user);
$em->flush();
}
return $this->render('eplateformeBundle:Default:register.html.twig',['form'=>$form->createView()]);
The view :
<div class="well">
{{ form_start(form ) }}
{{ form_errors(form) }}
{{ form_row(form.firstName) }}
{{ form_row(form.lastName) }}
{{ form_row(form.login) }}
{{ form_row(form.password) }}
{{ form_row(form.tel) }}
{{ form_row(form.email) }}
{{ form_row(form.address) }}
{{ form_widget(form.send, {'attr': {'class': 'btn btn-primary'}}) }}
{{ form_rest(form) }}
{{ form_end(form) }}
</div>
You can transfer own class to inputs fields like this:
<div class="well">
{{ form_start(form ) }}
{{ form_errors(form) }}
{{ form_row(form.firstName,{'attr':{'class':'your own class''}}) }}
{{ form_row(form.lastName,{'attr':{'class':'your own class''}}) }}
{{ form_row(form.login,{'attr':{'class':'your own class''}}) }}
{{ form_row(form.password,{'attr':{'class':'your own class''}}) }}
{{ form_row(form.tel,{'attr':{'class':'your own class''}}) }}
{{ form_row(form.email,{'attr':{'class':'your own class''}}) }}
{{ form_row(form.address,{'attr':{'class':'your own class''}}) }}
{{ form_widget(form.send, {'attr': {'class': 'btn btn-primary'}}) }}
{{ form_rest(form) }}
{{ form_end(form) }}
</div>

symfony change attribut 'for' form_label

I search in google but i don't find how to change( surcharging) the 'for' attribut in a form_label.
{{ form_widget(form.star,{'id':'rating-input-1-5','attr':{'class':'rating-input'}}) }}
{{ form_label(form.star,null,{'label_attr':{'class':'rating-star','for':'rating-input-1-5'}}) }}
{{ form_widget(form.star,{'id':'rating-input-1-4','attr':{'class':'rating-input'}}) }}
{{ form_label(form.star,null,{'label_attr':{'class':'rating-star','for':'rating-input-1-4'}}) }}
{{ form_widget(form.star,{'id':'rating-input-1-3','attr':{'class':'rating-input'}}) }}
{{ form_label(form.star,null,{'label_attr':{'class':'rating-star','for':'rating-input-1-3'}}) }}
{{ form_widget(form.star,{'id':'rating-input-1-2','attr':{'class':'rating-input'}}) }}
{{ form_label(form.star,null,{'label_attr':{'class':'rating-star','for':'rating-input-1-2'}}) }}
{{ form_widget(form.star,{'id':'rating-input-1-1','attr':{'class':'rating-input'}}) }}
{{ form_label(form.star,null,{'label_attr':{'class':'rating-star','for':'rating-input-1-1'}}) }}
I want that the form_label point on the id of my form_widget.
Is it possible ?
Thanks for your answer
Try to change form_label call to
{{ form_label(form.star,null,{'id':'rating-input-1-5', 'label_attr':{'class':'rating-star'}}) }}

Display error each field with twig

I have a problem with displaying errors with twig.
The errors are displayed in the last form_error with twig and I do not know how to fix it to display each error in his field.
I use annotation for constraints in my entity like * #Assert\True(message = "This field is empty")
{% trans_default_domain 'FOSUserBundle' %}
<form action="{{ path('fos_user_registration_register') }}" {{ form_enctype(form) }} method="POST" class="fos_user_registration_register" novalidate="novalidate">
{{ form_errors(form) }}
<article class="form-part part1">
<h2>1 - Information pour la création du compte</h2>
<label for="{{ form.pays.vars.id }}">Pays <span>*</span> : </label>
{{ form_widget(form.pays) }}
{{ form_errors(form.pays) }}
<label for="{{ form.username.vars.id }}">Pseudo <span>*</span> : </label>
{{ form_widget(form.username) }}
{{ form_errors(form.username) }}
<label for="{{ form.email.vars.id }}">Email <span>*</span> : </label>
{{ form_widget(form.email) }}
{{ form_errors(form.email) }}
{{ form_row(form.plainPassword) }}
<div class="birthday">
{{ form_row(form.birthday) }}
</div>
{{ form_row(form.nationalite) }}
</article>
<article class="form-part">
<h2>2 - Télécharger les 6 images de votre galerie</h2>
<div>
{{ form_row(form.images, {'label': ' '}) }}
</div>
</article>
<div class="bottom-form">
<div class="contrat-cgu">
<div>
{{ form_label(form.certificatAge) }}
{{ form_widget(form.certificatAge) }}
{{ form_errors(form.certificatAge) }}
Lire les Conditions générales d'utilisation
</div>
<div>
{{ form_label(form.artistContract) }}
{{ form_widget(form.artistContract) }}
{{ form_errors(form.artistContract) }}
Lire le Contrat artiste
</div>
</div>
{{ form_row(form.how) }}
{{ form_rest(form) }}
</div>
If someone has an idea

Categories