FormBuilder - achieving Bootstrap-styled forms

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Locked
Cerulean
Forum Members
Forum Members
Posts: 172
Joined: Mon Nov 01, 2010 8:56 am
Location: New Zealand

FormBuilder - achieving Bootstrap-styled forms

Post by Cerulean »

Bootstrap requires forms to be marked up as follows to receive Bootstrap styling:

Code: Select all

<div class="form-group">
    <label for="input1">My Label</label>
    <input type="text" class="form-control" id="input1">
</div>
Note the classes "form-control" on the input and "form-group" on the div wrapper.

FormBuilder allows a class for the div wrapper, but I can't see a way to get a class onto the input elements. Any suggestions?
allan1412
Forum Members
Forum Members
Posts: 24
Joined: Wed May 21, 2008 9:14 pm

Re: FormBuilder - achieving Bootstrap-styled forms

Post by allan1412 »

Cerulean
Forum Members
Forum Members
Posts: 172
Joined: Mon Nov 01, 2010 8:56 am
Location: New Zealand

Re: FormBuilder - achieving Bootstrap-styled forms

Post by Cerulean »

Thanks, but this template doesn't get a class onto the inputs as required.

Having looked into it some more, it seems that FormBuilder doesn't provide the type of control over the generated form that's needed. The form template allows some customisation, but whole chunks of HTML are still output via variables like {$entry->input} that are not customisable without editing the module files.
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1967
Joined: Mon Jan 29, 2007 4:47 pm

Re: FormBuilder - achieving Bootstrap-styled forms

Post by Jo Morg »

Cerulean wrote:(...) but whole chunks of HTML are still output via variables like {$entry->input} that are not customisable without editing the module files.
Not quite... there are two ways you can add a class to the entry:
  • - using Javascrip or JQuery to add a class;
  • - using smarty replace modifier, for instance: {$entry->input|replace:'class="':'class="addedclass '}
HTH
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
Cerulean
Forum Members
Forum Members
Posts: 172
Joined: Mon Nov 01, 2010 8:56 am
Location: New Zealand

Re: FormBuilder - achieving Bootstrap-styled forms

Post by Cerulean »

jQuery is the only solution I could find.

The replace modifier doesn't help in this case because FormBuilder renders the inputs without any class tag at all.
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1967
Joined: Mon Jan 29, 2007 4:47 pm

Re: FormBuilder - achieving Bootstrap-styled forms

Post by Jo Morg »

Find a common fixed part to replace, for instance:

Code: Select all

{$entry->input|replace:'id=':'class="addedclass" id='}
or something similar. I know it works because I use it all the time. ;)
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
Cerulean
Forum Members
Forum Members
Posts: 172
Joined: Mon Nov 01, 2010 8:56 am
Location: New Zealand

Re: FormBuilder - achieving Bootstrap-styled forms

Post by Cerulean »

Ahhh, didn't think of that... nice one.
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

Re: FormBuilder - achieving Bootstrap-styled forms

Post by psy »

FormBuilder gives you the option to write your own form templates on the 'Form Template' tab when editing the form.

Just leave all the logic that applies to errors etc and remove the foreach loop for the fields. Then you can hand-code the template fields stuff to suit Bootstrap (or zurb or whatever). The tab help gives you all the options and you can find your field info on the 'Submission Template' tab.
Cerulean
Forum Members
Forum Members
Posts: 172
Joined: Mon Nov 01, 2010 8:56 am
Location: New Zealand

Re: FormBuilder - achieving Bootstrap-styled forms

Post by Cerulean »

FormBuilder gives you the option to write your own form templates on the 'Form Template' tab when editing the form.
Good point - it is possible to get every form field by name and build the template field by field. Although this becomes a lot of work if you have a large number of fields and forms, and you have to keep the template and form in sync if you add/remove fields.
jac
New Member
New Member
Posts: 2
Joined: Sat Oct 18, 2014 9:06 pm

Re: FormBuilder - achieving Bootstrap-styled forms

Post by jac »

Hello Jo Morg ,
I try to work with cmsms but it is very hard .
I found very interesting your tip .
I try to put in place and I do not.
I searched but I'm stuck .
Can you give me a better explanation ..
I am newbie in cmsms .
But I 'm a fan .
Thank you in advance
Locked

Return to “Modules/Add-Ons”