I'm trying to replace the Prototype JavaScript framework version (1.5)
with the one into a PHP project using Zend framwork, Smarty
and Scriptaculus.

I do a Ajax.Request according to the parameters from the

The response is sent using this helper method:
        public function sendJson ($data)

                echo Zend_Json::encode($data);

So, I changed some lines to fit the Prototype JavaScript framework,
version in the
        onFormSuccess : function(transport) {
                // var json = transport.responseText.evalJSON(true); // <= v 1.5
                var json = transport.responseJSON;
                // var errors = $H(json.errors); // <= v 1.5
                var errors = json.errors;
                if (errors.length > 0) {
                        errors.each( function(pair) {
                                this.showError(pair.key, pair.value);
                } else {

But actually this code doesn't work since errors is an "Object" and
"length" property is undefined... (that's what i've seen in Firedebug)

So I would like to know how I can process "errors" object to retrieve
the key/value pairs.

"errors" object is managed by a "FormProcessor" object:
    abstract class FormProcessor
        protected $_errors = array();
        protected $_vals = array();
        private $_sanitizeChain = null;

        public function __construct()


        abstract function process(Zend_Controller_Request_Abstract

        public function sanitize($value)
            if (!$this->_sanitizeChain instanceof Zend_Filter) {
                $this->_sanitizeChain = new Zend_Filter();

            // filter out any line feeds / carriage returns
            $ret = preg_replace('/[\r\n]+/', ' ', $value);

            // filter using the above chain
            return $this->_sanitizeChain->filter($ret);

        public function addError($key, $val)
            if (array_key_exists($key, $this->_errors)) {
                if (!is_array($this->_errors[$key]))
                    $this->_errors[$key] = array($this->_errors

                $this->_errors[$key][] = $val;
                $this->_errors[$key] = $val;

        public function getError($key)
            if ($this->hasError($key))
                return $this->_errors[$key];

            return null;

        public function getErrors()
            return $this->_errors;

        public function hasError($key = null)
            if (strlen($key) == 0)
                return count($this->_errors) > 0;

            return array_key_exists($key, $this->_errors);

        public function __set($name, $value)
            $this->_vals[$name] = $value;

        public function __get($name)
            return array_key_exists($name, $this->_vals) ? $this->_vals
[$name] : null;



You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to