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'}}) }}
Related
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?
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>
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) }}
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) }}
Using this manual, I added dynamic field to my form. Now, how can I check existence of this field in my template?
{{ form_start(form) }}
{{ form_errors(form) }}
{% if ??? %} <---------------------------
{{ form_row(form.myDynamicField) }}
{% endif %}
{{ form_end(form) }}
What about,
{% if form.myDynamicField is defined %}
{{ form_row(form.myDynamicField) }}
{% endif %}
You may also need to check if form.myDynamicField is not null.
I know this question is a few years old, but you could also make it a shorter ternary operator.
{{ form.myDynamicField is defined ? form_row(form.myDynamicField) : null }}
{{ form_start(form) }}
{{ form_errors(form) }}
{% if form.getChildren['myDynamicField'] is defined %}
{{ form_row(form.myDynamicField) }}
{% endif %}
{{ form_end(form) }}