3

I'm trying to make a checkbox for "Terms of Use". This what I did so far:

->add('terms', 'checkbox', array(
            'mapped' => false,
            'required' => false,
            'label' => "J'accepte les Conditions Générales de Vente et les Conditions
                        Générales d'Utilisation",
            'attr' => array('style' => 'margin-left:-257px;'),
            'constraints' => new True(array('message' => "SVP acceptez les Conditions 
                                                          Générales de Vente et
                                                          les Conditions Générales
                                                          d'Utilisation")),
                ))

I want to make the section "Conditions Générales de Vente" of the label as a link to a PDF file for the user to read.

When the user clicks on that link an Ajax function will call a Controller that will render the PDF.

I just can't figure out how to add <a></a> inside the label.

M. A. Kishawy
  • 5,001
  • 11
  • 47
  • 72
Besbes Riadh
  • 811
  • 2
  • 10
  • 23
  • I assume you tried to add the link there... what happened? Did it get escaped? Just thoughts off the top of my head but... to me the FormType seems like the wrong place to do this - I would consider either doing this in the template itself - possibly messy, I know, but it feels like a more appropriate domain, or as a [custom field type](http://symfony.com/doc/current/cookbook/form/create_custom_field_type.html) with a hardcoded label, which involves some boilerplate but seems cleaner. – Darragh Enright Oct 02 '15 at 15:49
  • Thanks for the suggestions but I found a solution on another thread. Appareantly I didn't search that hard. Here's a link if you're interested by the answer: [link](http://stackoverflow.com/questions/17285070/symfony2-ewz-recaptcha-field-not-correctly-validating) – Besbes Riadh Oct 02 '15 at 19:55
  • 1
    Actually you can customize form rendering in twig and add link there – nowiko Oct 03 '15 at 13:02

2 Answers2

1

This question is old, but might help future visitors. I have found another easy way to generate links inside a label:

 //Set the links as variables
 {% set terms %}
   <a href="{{ path('terms_conditions') }}">terms &amp;conditions</a>
 {% endset %}
 {% set policy %}
     <a href="{{ path('privacy_policy') }}">privacy policy</a>
 {% endset %}

 //display the form and use the variables inside the label
 {{ form_start(paymentForm) }}
 {{ form_widget(paymentForm) }}
 <label for="transaction_terms">I have read and accept the {{ terms }} and {{ policy }}.</label>
 {{ form_end(paymentForm) }}
Helenesh
  • 3,999
  • 2
  • 21
  • 36
0

Looks like someone else has had a similar issue (wanting to use HTML within the label tag content).

See HTML in Symfony2 form labels, looks like you need to use form theming.

Community
  • 1
  • 1
Adambean
  • 1,096
  • 1
  • 9
  • 18