Categories
Coding PHP Zend Framework

Posting Defaults for Checkboxes

I was playing around with Zend_Form a little while ago and I realized they did something neat with checkboxes.

Everytime I created a checkbox, Zend made two.

<input id="optInDefault" name="optIn" type="hidden" value="n" />
<input id="optIn" name="optIn" type="checkbox" value="y" />

One hidden, and one not.  This is handy because when the user doesn’t check it – the hidden value gets posted. When the checkbox is selected, that value overrides the hidden one.

This also works for radio buttons, or any other form element where you want a default value posted.

Categories
PHP Zend Framework

Zend Framework, Rewrite Rules, Apache

Most of the Zend Framework documentation I’ve read recommends a rewrite rule that looks something like this:

RewriteEngine on
RewriteRule !\.(swf|js|ico|gif|jpg|png|css)$ index.php

Why not use a more elegant rule that looks like this:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php

This rule basically says: If it’s not an existing file, and it’s not an existing directory – pass the request through index.php.

This allows you far more flexibility when you want to host non-framework files, or a whole slew of other media types that are not listed in your apache configuration.

Categories
PHP

Zend Framework 1.6, and more.

Zend released version 1.6 of their framework just a short while ago and I’ve been reviewing a lot of the changes.  As it turns out this framework is becoming quite large and diverse in what it can do.  Some of the newer features that interest me:

  • Saving sessions to a database table.
  • Dojo integration
  • Captcha and File upload form elements.

The saving sessions to a database table is conveniently easy, but I’m not too sure how well it will fare once I really get going.  It’s so simple that I’m not sure how well it’ll handle validating and securing sessions (based on Users IP, or web browser agent).  But we’ll see.

Dojo integration doesn’t really excite me that much. I’m a big fan of Prototype and Scriptaculous, and having another Javascript framework just sitting there seems like a waste of space to me – but again, it’s something I haven’t exactly dove into yet.  Maybe dojo rocks my socks and I just haven’t felt it yet.

And finally, the captcha and file uploaders may seem very trivial, but trust me – when you’re trying to build a site and those two elements were unavailable for use with Zend_Form — it was a big pain in the ass and effectively made Zend_Form useless when you needed those two elements.

Things are looking good, and the new source base for pileofcrap.org is getting there.  Of course every time I go to work on it I get distracted and then when I return to working on it a new version of ZF is out. Go figure!