Hi,

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

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

The response is sent using this helper method:
        public function sendJson ($data)
        {
                $this->_helper->viewRenderer->setNoRender();

                $this->getResponse()->setHeader('Content-type', 
'application/json');
                echo Zend_Json::encode($data);
        }

So, I changed some lines to fit the Prototype JavaScript framework,
version 1.6.0.3 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) {
                        this.form.down('.error').show();
                        errors.each( function(pair) {
                                this.showError(pair.key, pair.value);
                        }.bind(this));
                } else {
                        this.form.submit();
                }
        }

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:
<?php"
    abstract class FormProcessor
    {
        protected $_errors = array();
        protected $_vals = array();
        private $_sanitizeChain = null;

        public function __construct()
        {

        }

        abstract function process(Zend_Controller_Request_Abstract
$request);

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

            // 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
[$key]);

                $this->_errors[$key][] = $val;
            }
            else
                $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;
        }
    }
?>

thanks,

Romain

--~--~---------~--~----~------------~-------~--~----~
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 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to