Issue with resizing fields of form under symfony 3 - php

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>

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?

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'}}) }}

How to customize FOSUserBundle forms

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) }}

How to populate a radio button in laravel by using form::model

I am populating a radio button by using form::model in laravel. The populate form is in blade php. Why is the radio button not populating automatically like the textarea, textbox and drop down list?
{{ Form::model($teacher, array('route'=> array('updateteacher', $teacher->id))) }}
{{ Form::label('gender', 'Enetr your gender') }}
{{ Form::label('male', 'Male') }}
{{ Form::radio('gender', 'male') }}
{{ Form::label('famle', 'Female') }}
{{ Form::radio('gender', 'female', $teacher->gender==1) }}
{{ Form::close() }}
I'm working in laravel 4.2, the table name is teacher and column name is gender.
I think the correct syntax is like ($teacher->gender == 'male') which is in your case:
{{ Form::model($teacher, array('route'=> array('updateteacher', $teacher->id))) }}
{{ Form::label('gender', 'Enter your gender') }}
{{ Form::label('male', 'Male') }}
{{ Form::radio('gender', 'male', ($teacher->gender == 'male')) }}
{{ Form::label('female', 'Female') }}
{{ Form::radio('gender', 'female', ($teacher->gender == 'female')) }}
{{ Form::close }}
And don't forget the Form::close.
I am not sure with 4.2 but try
{{ Form::model($teacher, array('route'=> array('updateteacher', $teacher->id)))}}
{{ Form::label('gender','Enter your gender') }}
{{ Form::label('male','Male')}}
{{ Form::radio('gender' , 'male', $teacher->gender) }}
{{ Form::label('female','Female') }}
{{ Form::radio('gender', 'female', $teacher->gender) }}
If that doesn't work try this.
{{ Form::model($teacher, array('route'=> array('updateteacher', $teacher->id)))}}
{{ Form::label('gender','Enetr your gender') }}
{{ Form::label('male','Male')}}
{{ Form::radio('gender' , 'male', ($teacher->gender==true)?1:0) }}
{{ Form::label('female','Female') }}
{{ Form::radio('gender', 'female', ($teacher->gender==true)?1:0) }}

Categories