As you can see, "onFormSuccess" method is bound to the "onSuccess"
callback of the Ajax.Request

        onSubmit : function(e) {
                Event.stop(e);
                var options = {
                        parameters : this.form.serialize(),
                        method : this.form.method,
                        //requestHeaders: {Accept: 'application/json'}, // <- I 
don't know
if it's useful
                        onSuccess : this.onFormSuccess.bind(this)
                };
                this.resetErrors();
                new Ajax.Request(this.form.action, options);
        },

Actually, my problem is that I don't know how to convert the "errors"
object (from transport.responseJSON.errors) to be able to do the same
thing as the version 1.5:
onFormSuccess : function(transport)
{
    var json = transport.responseText.evalJSON(true);
    var errors = $H(json.errors);
    if (errors.size() > 0) {
        this.form.down('.error').show();
        errors.each(function(pair) {
            this.showError(pair.key, pair.value);
            }.bind(this));
    } else {
        this.form.submit();
    }
}

Actually, i think the main trouble is because the new version of Hash
(since the 1.6.0_rc1, October 16, 2007) is NOT backwards compatible
with the former Hash class.

On 8 oct, 14:22, "Alex McAuley" <webmas...@thecarmarketplace.com>
wrote:
> I dont think "onFormSuccess" is  valid.. i think it was changed to
> "onSuccess" but check the docs just incase
>
> HTH
> Alex Mcauleyhttp://www.thevacancymarket.com
>
> ----- Original Message -----
> From: "Romain Dequidt" <dequidt.rom...@gmail.com>
> To: "Prototype & script.aculo.us" <prototype-scriptaculous@googlegroups.com>
> Sent: Wednesday, October 07, 2009 7:28 PM
> Subject: [Proto-Scripty] prototype.js from 1.5 from 1.6 in Zend Framework
>
> > 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