MatTheCat
MatTheCat

Reputation: 18721

How should I embed a paragraph in a Symfony2 form?

I use the Symfony2 form component to create a registration form and I just want to add a paragraph saying the user must understand terms of service above the submit button.

Should I create a ParagraphType and use it in the controller or override the submit button's block and add the paragraph in the template?

Neither of these suits me. Is there a better solution?

Thanks!

Upvotes: 1

Views: 379

Answers (2)

sjagr
sjagr

Reputation: 16502

Without breaking the form into separate fields using form_widget for each field so you can inject a paragraph between the later part of the form and the submit button, you are restricted to using only form elements, meaning you can either create a special Form Type or use a form element. So under that logic, you can just make the "I understand the terms of service" a part of the form itself!

$builder->add('tos', 'checkbox', array(
    'label'     => 'I agree with the Terms of Service',
    'required'  => true,
));

Upvotes: 1

s7anley
s7anley

Reputation: 2498

Easy fix, just don't add submit button as field of form and manually render it in view. This way, you can add also some paragraph before it.

Upvotes: 1

Related Questions