Processing two forms on the same page is not the simplest task in the Zend Framework. About a year ago I encountered this problem and studied others’ approaches. Eventually I hacked together a solution with multiple actions and lots of redundant code. But I was recently making updates to this page and found a more elegant method for handling multiple forms.
On some projects I use the Doctrine Object Relational Mapper, a fantastic library for modeling database objects. To combine it with Zend Framework 1, I use Guilherme Blanco’s Bisna application resource. I recently upgraded a project to the latest version of Doctrine and suddenly couldn’t autoload the Symphony classes. It took far too long for me to figure out the problem, so I hope I can spare someone else the same trouble.
To use a reserved character in a URL without invoking its special meaning, the character must be URL encoded. For example, a
? separates the page name from the query string, a
& separates query string parameters, and a
= separates parameter names from their values. These characters must be converted to
%3D respectively if we want them interpreted literally.
In MVC applications, these special characters are less common because URLs follow a pattern like
/Module/Controller/Action/Parameter1/Parameter2. In this case, the most important reserved character is the forward slash. Let’s see how to handle slashes in Zend Framework 1 URLs.
Forms are a tricky part of any Model-View-Controller (MVC) application. They incorporate validation, presentation, and security logic that spans all tiers of the application. Separating these concerns is difficult but important. I’ll walk through how I use
Zend_Form in Zend Framework 1, but the same principles should apply to any MVC application.
If you want to include a
<fieldset> in your
Zend_Form, you might try the
Zend_Form_Decorator_Fieldset decorator. But it’s not apparent that this decorator is meant for the form and not the individual elements in it. Instead, here’s a custom decorator to render your
Zend_Form_Element with a
What if you need to validate input using a callback function that will return False when the input is valid? Here’s a custom validator to do the job.
This class is super simple, so we’ll begin with the code.
class My_Validate_Callback_NoContext extends Zend_Validate_Callback
public function isValid($value)