Make a symfony2 form label into a link












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.










share|improve this question

























  • 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 with a hardcoded label, which involves some boilerplate but seems cleaner.

    – Darragh Enright
    Oct 2 '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

    – Besbes Riadh
    Oct 2 '15 at 19:55






  • 1





    Actually you can customize form rendering in twig and add link there

    – nowiko
    Oct 3 '15 at 13:02
















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.










share|improve this question

























  • 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 with a hardcoded label, which involves some boilerplate but seems cleaner.

    – Darragh Enright
    Oct 2 '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

    – Besbes Riadh
    Oct 2 '15 at 19:55






  • 1





    Actually you can customize form rendering in twig and add link there

    – nowiko
    Oct 3 '15 at 13:02














3












3








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.










share|improve this question
















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.







forms symfony






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 2 '15 at 15:21









M. A. Kishawy

2,932103865




2,932103865










asked Oct 2 '15 at 15:18









Besbes RiadhBesbes Riadh

3381520




3381520













  • 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 with a hardcoded label, which involves some boilerplate but seems cleaner.

    – Darragh Enright
    Oct 2 '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

    – Besbes Riadh
    Oct 2 '15 at 19:55






  • 1





    Actually you can customize form rendering in twig and add link there

    – nowiko
    Oct 3 '15 at 13:02



















  • 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 with a hardcoded label, which involves some boilerplate but seems cleaner.

    – Darragh Enright
    Oct 2 '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

    – Besbes Riadh
    Oct 2 '15 at 19:55






  • 1





    Actually you can customize form rendering in twig and add link there

    – nowiko
    Oct 3 '15 at 13:02

















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 with a hardcoded label, which involves some boilerplate but seems cleaner.

– Darragh Enright
Oct 2 '15 at 15:49





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 with a hardcoded label, which involves some boilerplate but seems cleaner.

– Darragh Enright
Oct 2 '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

– Besbes Riadh
Oct 2 '15 at 19:55





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

– Besbes Riadh
Oct 2 '15 at 19:55




1




1





Actually you can customize form rendering in twig and add link there

– nowiko
Oct 3 '15 at 13:02





Actually you can customize form rendering in twig and add link there

– nowiko
Oct 3 '15 at 13:02












2 Answers
2






active

oldest

votes


















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.






share|improve this answer

































    0














    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) }}





    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f32910479%2fmake-a-symfony2-form-label-into-a-link%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      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.






      share|improve this answer






























        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.






        share|improve this answer




























          0












          0








          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.






          share|improve this answer















          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.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited May 23 '17 at 12:17









          Community

          11




          11










          answered Oct 9 '15 at 4:06









          AdambeanAdambean

          411310




          411310

























              0














              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) }}





              share|improve this answer




























                0














                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) }}





                share|improve this answer


























                  0












                  0








                  0







                  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) }}





                  share|improve this answer













                  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) }}






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 21 '18 at 18:37









                  HeleneshHelenesh

                  933920




                  933920






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f32910479%2fmake-a-symfony2-form-label-into-a-link%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

                      Alcedinidae

                      RAC Tourist Trophy