服务器端验证magento 1.9如何做?

时间:2019-02-20 12:09:35

标签: php magento-1.9

我在模型中创建了一个验证函数,当将数据保存到数据库中时如何将其应用于表单?

public function validate() {
        $errors = array();
        if (!Zend_Validate::is($this->getName(), 'NotEmpty')) {
            $errors[] = 'Name is needed';
        }
        if (!Zend_Validate::is($this->getEmail(), 'NotEmpty')) {
            $errors[] = 'Email is needed';
        }

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

保存到数据库中时如何将其应用于我的表单?

保存功能

public function postAction()
    {

        $data = $this->getRequest()->getPost();
        $session = Mage::getSingleton('core/session');
        $person = Mage::getModel('feedback/block');
        $person->setData('name', $data['name']);
        $person->setData('email', $data['email']);
        $person->setData('phone', $data['phone']);
        if(($data['subject']) == 'other'){
            $person->setData('subject', $data['other']);
        }
        else {
            $person->setData('subject', $data['subject']);
        }
        $person->setData('massage', $data['massage']);
        $person->setData('status', '0');   
        try {
            $person->save();
            $session->addSuccess('Thank for you feedback');
        } catch (Exception $e) {
            $session->addError('Error');
        }
        $this->_redirect('feedback/index/index');
 }
}

0 个答案:

没有答案