php codeigniter表单验证



我的视图:

<div class="row eva-add-mainbox">
            <div class="col s3 eva-aditem-leftbox">
                <p>Product Item Name</p>
            </div>
            <div class="col s9">
                <div class="input-field col s12">
                    <input type="text" name="pname" class="validate" id="proName">
                    <label for="icon_prefix">Product Item Name</label>
                </div>
            </div>
        </div>

我的控制器: -

$this->form_validation->set_rules('itemCode', 'Item Code', 'trim|required|min_length[2]|max_length[38]|xss_clean');
    $this->form_validation->set_rules('pDescription', 'Product Description', 'trim|required|min_length[2]|max_length[38]|xss_clean');
    $this->form_validation->set_rules('productPrice', 'Price', 'required|max_length[12]|regex_match[/^[0-9.]+$/]|xss_clean');
    $this->form_validation->set_rules('proQuantity', 'Quantity', 'max_length[12]|numeric|greater_than[0]|xss_clean');
    $this->form_validation->set_rules('pname', 'Name', 'trim|required|min_length[2]|max_length[38]|xss_clean');
    if($this->form_validation->run() == TRUE) {
        if ($_FILES["file"]["name"] != '') {
            $test = explode('.', $_FILES['file']['name']);
            $extension = end($test);
            $name = rand(100, 999) . '.' . $extension;
            $location = './images/' . $name;
            move_uploaded_file($_FILES['file']['tmp_name'], $location);
            $b = $this->session->userdata('business');
            $pdata['product_code'] = $this->input->post('itemCode');
            $pdata['title'] = $this->input->post('pName');
            $pdata['discription'] = $this->input->post('description');
            $pdata['business_id'] = $b->biz_id;
            $pdata['price'] = $this->input->post('price');
            $proQuantity = $this->input->post('proQuantity');
            $pdata['image'] = $location;
            $pAttribute = $this->input->post('pAttribute');
            $pValue = $this->input->post('pValue');
        }
        $result = $this->product_model->setProductData($pdata, $pAttribute, $pValue, $proQuantity);
    }else
    {
        echo validation_errors();
    }

我遇到一个错误,例如:

需要产品描述字段。

需要价格字段。

需要名称字段。

任何人都可以解释为什么会发生吗?

在验证中,您验证这三个字段就是为什么它的到来

$this->form_validation->set_rules('pDescription', 'Product Description', 'trim|required|min_length[2]|max_length[38]|xss_clean');
 $this->form_validation->set_rules('proQuantity', 'Quantity', 'max_length[12]|numeric|greater_than[0]|xss_clean');
    $this->form_validation->set_rules('pname', 'Name', 'trim|required|min_length[2]|max_length[38]|xss_clean');

最新更新