检查验证 OpenCart

check validate OpenCart

我正在尝试检查验证。在 PrestaShop 我是这样做的:

  if (empty($email)) {
        $this->errors[] = Tools::displayError('Email is empty.');
        $this->doLog('ERROR: Email/username is empty');
    } elseif (!Validate::isEmail($email)) {
        $this->errors[] = Tools::displayError('Invalid email address.');
        $this->doLog('ERROR: Invalid Email address');
    }

有人知道如何在 OpenCart 中执行此操作吗?

谢谢

例如打开这个文件:

catalog/controller/information/contact.php

你会看到validate function:

protected function validate() {
    if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 32)) {
        $this->error['name'] = $this->language->get('error_name');
    }

    if (!filter_var($this->request->post['email'], FILTER_VALIDATE_EMAIL)) {
        $this->error['email'] = $this->language->get('error_email');
    }

    if ((utf8_strlen($this->request->post['enquiry']) < 10) || (utf8_strlen($this->request->post['enquiry']) > 3000)) {
        $this->error['enquiry'] = $this->language->get('error_enquiry');
    }

    // Captcha
    if ($this->config->get($this->config->get('config_captcha') . '_status') && in_array('contact', (array)$this->config->get('config_captcha_page'))) {
        $captcha = $this->load->controller('extension/captcha/' . $this->config->get('config_captcha') . '/validate');

        if ($captcha) {
            $this->error['captcha'] = $captcha;
        }
    }

    return !$this->error;
}

在那个文件中,您还可以看到这个函数是如何使用的:

if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {