Making CakePHP Form Helper Compatible with Bootstrap
I’ve been struggling getting inputs created by the CakePHP Form Helper to function sanely with a bootstrap admin theme we’re using at work. When I first looked at the form helper I thought it was silly to using PHP to generate HTML. But there are good reasons to do this:
- Less HTML to change
- Bind CSS classes to form elements in a single location
- Integration with CakePHP security components like CSRF.
- Baking templates will use the Form Helper by default.
Since we use customize bake scripts to automate CRUD views as well as the security component I needed to roll up my sleeves and make the Form Helper compatible with our Bootstrap theme.
Our default form behavior looks this:
This is not what we want and it might lead you to wrap HTML around this form helpers. This is a waste of key strokes and makes our HTML far to static and thus resistant to future UI changes. Using form templates we can adjust the form helpers default template and achieve a much more agile UI.