I am fighting with customize on symfony forms for twig...
My problem is that I want a specific look and feel for a field. Here is the code :
class FormType extends AbstractType
{
//Builds the form
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('url', UrlType::class, array(
'label' => false,
'required' => true,
))
;
}
}
{# Twig template #}
{% form_theme form _self %}
{{ form_start(form) }}
{{ form_widget(form) }}
{% block url_widget %}
<div class="col-md-12">
<span class="input-group-addon">url</span>
<input type="url" id="url" name="url" class="form-control input-lg" />
</div>
{% endblock url_widget %}
<div class="form-group text-center">
<button type="submit" name="submit" title="send">
Send
</button>
</div>
{{ form_end(form) }}
But when I use this I have two fields in place of one.
[EDIT : split in 3 questions due to on hold status]
[EDIT 2 : solution found] As the question is still on hold (and in case it's displayed one day), I put the solution I've found, below.
As my field is named url
it conflicts with url_widget
(I think) so I have overrided both the standard block url_widget
and the full name url_url_widget
. The code is the following:
{% form_theme form _self %}
{% block content %}
{{ form_start(form) }}
{{ form_widget(form) }}
{% block url_widget %}
{% endblock url_widget %}
{% block url_url_widget %}
<div class="col-md-12">
<span class="input-group-addon">url</span>
<input type="url" id="url" name="url" class="form-control input-lg" />
</div>
{% endblock url_url_widget %}
<div class="form-group text-center">
<button type="submit" name="submit" title="send">
Send
</button>
</div>
{{ form_end(form) }}
{% endblock %}
Another solution is to rename my field in my FormType, what I will probably do...