..check it out the Foldi blog for updates on work, clients, etc...

Archive for April, 2009


Breaking up a form across multiple pages in CakePHP

Tuesday, April 21st, 2009

Most CakePHP form examples present all the fields on one page and assume users fill everything out at once. But there may be a time when you need to spread a model’s form fields over multiple pages.

This approach brings with it a few important requirements.

1. You should allow the user to go forward and back through the pages to see their input and allow for editing.

2. You should not be able to manipulate the URL to skip ahead.

3. There should be a progress indicator (ie. step 1 of 4, step 2 of 4, etc).

4. The final page should summarize all the info input by the user.

This example came from a recent project where I couldn’t use temporary tables to store my data across the pages. I was also using CakePHP’s Tree behavior on some pages and was reluctant to store the data hierarchy in session variables. So below is an explanation of how I did it just reading in and out of one model. I also provided a working demo.

(more…)

An easy and intelligent pagination menu for CakePHP

Tuesday, April 7th, 2009

I recently needed to create a typical paginated directory page where people could browse via an alphabetical menu. So clicking ‘A’ returns all entries that begin with ‘A’, ‘B’ with ‘B’ and so on. CakePHP’s Paginator Helper made this all very easy.

However, there was one tricky requirement….in the menu, if there were no records that began with a corresponding letter, that letter should not be clickable. This meant before I displayed the contents of my directory page, I needed to get quite a bit of information about the database table…which letters never appear as the first letter of a record? With a table that stores 1000s of records, this could have added some dangerous overhead to this page.

So here’s my solution.

(more…)