Вопрос

I need your help. I have build a form of user registration. I need to add checkbox with this massage: "Accept the terms of use" but the word of "terms" must be link to pdf file. Of course I can't put html tags into translation file because it doesn't work. I could use 'raw' keyword in twig template. But I don't want to doing this. I am thinking about placeholder to do it. But I do not now how to made it form class. Do you have any idea how to do it?

class SupplierAddressFormType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        parent::buildForm($builder, $options);
         $builder->add('roules_acceptance', 'checkbox', array('label' => 'form.roules_acceptance', 'mapped' => false));
         // ....
    }
}

example of label what I need to made:

Accept the <a href="url_to_pdf">terms</a>
Это было полезно?

Решение 3

Thx for yours help.

Finally I sloved it by using twig template. Finally I solved it by using twig template. My example below explain everything:

    <div>
        {{ form_widget(form.sfGuardUserProfile.roulesAcceptance) }}
        {{ 'form.roules_acceptance'| trans | raw }}  {# <---- my answer #}
        {{ form_errors(form.sfGuardUserProfile.roulesAcceptance) }}     
    </div>
    <div>
        {{ form_widget(form.sfGuardUserProfile.allowToUsePersonalData) }}
        {{ form_label(form.sfGuardUserProfile.allowToUsePersonalData) }}
        {{ form_errors(form.sfGuardUserProfile.allowToUsePersonalData) }}     
    </div>

Другие советы

By placeholder, are you talking about html one? You can put any html tag in any form type by using the attr option.

For example:

$builder->add('field', 'text', array('attr' => array('foo' => 'bar')));

will generate:

<input type="text" foo="bar" />

Hope, this is what you're looking for!

EDIT:

You issue is about templating, so I recommend you to play with the form theming. For example, you have a form named user_form and a field named field, then, create a twig template with a block named user_form_field_label and put your html as you want in this block. Then, just need to apply your theme on your specific form by using the form_theme twig primitive.

Everything is explained here.

My approach would be not to put the html in the label but to use a 'normal' label, e.g. 'terms'. The link I would set in the twig template, e.g.

Accept the <a href="url-to-pdf"> {{ form_label(your-form-item) }} </a>

Hope that helps.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top