Search code examples
htmlcakephpxhtmlstandards-complianceformhelper

Is CakePhp 'standards compliant' when generating HTML, Forms, etc?


So I've been reading a lot of "Designing with Web Standards" and really enjoying it. I'm a big CakePhp user, and as I look at the source for various form elements that Cake creates with its FormHelper, I see all sorts of extraneous

In the book, he promotes semantic HTML, and writing your markup as simple / generic as possible.

So my question is, am I better writing my own HTML in these situations? I really want to work in compliance with XHTML and CSS standards, and it seems I'd spend just as much time (if not more) cleaning up Cakes HTML, when I could just write my own

thoughts?

p.s. Here's an example in an out of the box form that CakePhp generates using the FormHelper

<form id="CompanyAddForm" method="post" action="/omni_cake/companies/add" accept-charset="utf-8"><div style="display:none;"><input type="hidden" name="_method" value="POST" /></div>       <div class="input text required"><label for="CompanyName">Name</label><input name="data[Company][name]" type="text" maxlength="50" id="CompanyName" /></div>        <div class="input text required"><label for="CompanyWebsite">Website</label><input name="data[Company][website]" type="text" maxlength="50" id="CompanyWebsite" /></div>        <div class="input textarea"><label for="CompanyNotes">Notes</label><textarea name="data[Company][notes]" cols="30" rows="6" id="CompanyNotes" ></textarea></div>        <div class="submit"><input type="submit" value="Submit" /></div></form>

EDIT: An in an indented form (indentation does not effect the standards compliance issue, but the above one-liner style is nearly impossible to read):

<form id="CompanyAddForm" method="post" action="/omni_cake/companies/add" accept-charset="utf-8">
    <div style="display:none;">
       <input type="hidden" name="_method" value="POST" />
    </div>
    <div class="input text required">
        <label for="CompanyName">Name</label>
        <input name="data[Company][name]" type="text" maxlength="50" id="CompanyName" />
    </div>
    <div class="input text required">
        <label for="CompanyWebsite">Website</label>
        <input name="data[Company][website]" type="text" maxlength="50" id="CompanyWebsite" />
    </div>
    <div class="input textarea">
        <label for="CompanyNotes">Notes</label>
        <textarea name="data[Company][notes]" cols="30" rows="6" id="CompanyNotes" ></textarea>
    </div>
    <div class="submit">
        <input type="submit" value="Submit" />
    </div>
</form>

In the above, there's those couple divs that seem unnecessary like the one that has inline CSS "display:none". I realized I can change classes and IDs of all the fields, but if I'm doing do that for each one, I might as well write the HTML myself...


Solution

  • My answers to your two questions are as follows:

    Is CakePhp 'standards compliant' when generating HTML, Forms, etc?

    Yes.

    In [Designing with Web Standards], he promotes semantic HTML, and writing your markup as simple / generic as possible. So my question is, am I better writing my own HTML in these situations?

    Sometimes you are better off, sometimes you're not. If your goal is to use minimal, semantic markup, you could be better off writing your own HTML most of the time. However, if your goal is to generate standards compliant HTML quickly, then allowing Cake to be what it's meant to be—a rapid development framework—is a good idea.

    That said, you can tell Cake not to print some of its markup when you find it unnecessary. For example, you can suppress the div elements that wrap form inputs by using a value of false with this option: http://book.cakephp.org/view/1397/options-div