Asked  7 Months ago    Answers:  5   Viewed   35 times

I've started to use Symfony2 but I've some problems. I wanted to render fields by hand but it doesn't work because my field yet rendered by me is displayed with the form_rest() function too, so I have two same fields.

Here is my code :

<div>
     {{ form_errors(form.contenu) }}
     <textarea id="{{ form.contenu.vars.id }}" name="{{ form.contenu.vars.full_name }}">{{ form.contenu.vars.value }}</textarea>
</div>

And, at the form's end, I must put this :

{{ form_rest(form) }}

But it displays the "contenu" field :(

Do you have an idea of what's the problem ?

 Answers

23

Another option is to explicitly mark the field as rendered:

{% do form.contenu.setRendered %}
Wednesday, March 31, 2021
 
weegee
answered 7 Months ago
16

You have to pass an instance of SymfonyComponentFormFormView instead of SymfonyComponentFormForm to your view.

Fix this using ...

... ->getForm()->createView();

FormBuilder::getForm builds the Form object ... Form::createView then creates a FormView object.

Saturday, May 29, 2021
 
fret
answered 5 Months ago
98

you need render your form on layout twig by:

 public function indexAction(){
    $form = $this->createForm(new ContactType());
    return $this->render('YodaHomeBundle::layout.html.twig',array('form' => $form->createView());

}

Or you can split layout, one controller is one layout:

Controller:

class HomeController extends Controller{

/**
  * @Route("/home", name="homePage")
  * @Template()
  *
  */
public function indexAction(){

    return $this->render('YodaHomeBundle::layout.html.twig');

}

public function contactAction(Request $request)
{

    $form = $this->createForm(new ContactType());
    // do your code

    return array(
        'YodaHomeBundle::contactlayout.html.twig',
    array('form' => $form->createView());

}

}

And for TWIG: layout.html.twig:

[..]
<div>{{ render(controller('YodaHomeBundle:Home:contact')) }}</div>
[..]

contactlayout.html.twig:

[..]
    <form action="{{ path('mail_create') }}" method="post">
                {{ form_start(form) }}
                {{ form_widget(form) }}
                {{ form_end(form) }}
    </form>
[..]
Saturday, May 29, 2021
 
Chvanikoff
answered 5 Months ago
33

I think this will work

 <legend><span>ur text</span></legend>

Give border to the legend tag

legend {padding: 2px;border: 1px solid green;}
Friday, September 10, 2021
 
Ivan Mushketyk
answered 1 Month ago
26

Bind AveragePrice to the FormattedText property, and remove the StringFormat.

<Label FormattedText="{Binding AveragePrice}" HorizontalTextAlignment="Center" />
Saturday, October 16, 2021
 
Maxime VAST
answered 2 Days ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :