1

I'm Validating Address in Customer Register Page, it's working fine Error also displaying in same page. After displaying error message the form is lose viewstate (entered user data).

my code is:

public function createPostAction(){

        $valid = $this->_validation();
        $arguments = $this->getRequest()->getPost();

        if( $valid === true){
            parent::createPostAction();
        }else{

            $this->_redirect('*/*/create',$arguments);
        }
    }

    protected function _validation()
    {
        $errors = array();

        $continue = Mage::helper('addressapi/data')->Address($this->getRequest()->getPost(), 'customer');
        if (!$continue) {
            $errors[] = Mage::getSingleton('core/session')->addError('Please Enter the Correct Address details.');
        }

        if (empty($errors)) {
            return true;
        }


        return $errors;
    }

How can I bind viewstate data after form postback.

Thanks in advance.

1

You can save the values send through post in the session.
Something like this:

public function createPostAction(){

    $valid = $this->_validation();
    $arguments = $this->getRequest()->getPost();

    if( $valid === true){
        parent::createPostAction();
    }else{
        Mage::getSingleton('core/session')->setAddressapiPostData($arguments);
        $this->_redirect('*/*/create',$arguments);
    }
}

Then in the template that renders the form check if there is any data in the session.

$sessionValues = Mage::getSingleton('core/session')->getAddressapiPostData(true); 

The true parameter will make Magento retrieve the values and remove them from the session so you won't see the same values the next time you view the form.
If there are any values in the var $sessionValues add them to the form. Each field for each input.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.