peter_jackson
peter_jackson

Reputation: 91

Symfony2 How to use a front end template other than the default form

I am not familiar with the front end, and could use some help/guidance on how to replace the default {{ form }} template and use the other one provided.

How do I include in or swap out this html into my Symfony2 form?

Here is a screen shot: (the form I want to use is on top and the Symfony2 form template is underneath) enter image description here

Contact Form:

<div class="row">
    {{ form_errors(form) }}
    <div class="form-group col-lg-4">
        <label>Name</label>
        <input type="text" class="form-control">
        {{ form_row(form.name) }}
    </div>
    <div class="form-group col-lg-4">
        <label>Email Address</label>
        <input type="email" class="form-control">
        {{ form_row(form.email) }}
    </div>
    <div class="form-group col-lg-4">
        <label>Phone Number</label>
        <input type="tel" class="form-control">
        {{ form_row(form.phone) }}
    </div>
    <div class="clearfix"></div>
    <div class="form-group col-lg-12">
        <label>Message</label>
        <textarea class="form-control" rows="6"></textarea>
        {{ form_row(form.message) }}
    </div>
    <div class="form-group col-lg-12">
        <input type="hidden" name="save" value="contact">
        <button type="submit" class="btn btn-default">Submit</button>
    </div>
    {{ form_rest(form) }}
</div>

Upvotes: 0

Views: 161

Answers (1)

Tomasz Madeyski
Tomasz Madeyski

Reputation: 10890

Basically what you need to do is create your own theme overriding default Symfony themes which you can find in form_div_layout.html.twig file located in src/Symfony/Bridge/Twig/Resources/views/Form.

You need to check form themes docs which is quite well written and all you need to know is already there.

Upvotes: 3

Related Questions