Method: process

When the user submits their chosen options for the container rule, this method is called. At this point you must process their values to ensure they are valid. This stage will typically involve three parts for each value you want to process:

  1. Read a value from the $request object.

  2. If the value is valid, write it to the form process using $fp->set('name', $val).

  3. If the value is invalid, write an error message to the form processor using $fp->addError('name', 'Some error message to display').

Tip

You can learn more about the Zend_Controller_Request_Abstract class at http://framework.zend.com/manual/en/zend.controller.request.html.

If no errors are reported, the container rule is saved with the options you write to the form processor. If one or more errors are reported then the user will be shown the error message(s).

The following example demonstrates reading the weather value submitted by the user and acting accordingly. In this example we make use of the data returned by getEditorData()

Note

We haven't yet covered how to display an option to the user to select the location, but we'll cover this next.

Example 3.3. Processing a user-submitted value

<?php
    class Driver_containers_rule_weather_controller extends Module_Containers_Driver_Abstract
    {
        // ...
        
        public function process(FormProcessor $fp, Zend_Controller_Request_Abstract $request)
        {
            $location = $request->getPost('location');
            
            if (in_array($location, $this->getEditorData())) {
                $fp->set('location', $location);
            }
            else {
                $fp->addError('location', 'Please select a valid location');
            }
        }
        
        // ...
    }
?>