我的观点:
<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();
}
我收到错误:
“产品说明”字段是必需的。
价格字段是必需的。
名称字段是必需的。
任何人都能解释为什么会这样吗?
答案 0 :(得分:1)
在验证中,您验证了这三个字段,这就是它即将发生的原因
$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');