Php CodeIgniter-表单验证集为false

Php CodeIgniter-表单验证集为false,php,forms,codeigniter,validation,Php,Forms,Codeigniter,Validation,我有一些图像上传脚本,我正在使用它进行表单验证。这就是代码: $this->form_validation->set_rules('name','Name','required|max_length[30]|xss_clean'); $this->form_validation->set_rules('desc','Description','required|xss_clean'); if ($this->form_validation->run() ==

我有一些图像上传脚本,我正在使用它进行表单验证。这就是代码:

$this->form_validation->set_rules('name','Name','required|max_length[30]|xss_clean');
$this->form_validation->set_rules('desc','Description','required|xss_clean');

if ($this->form_validation->run() == TRUE)
{
    $config = array(
        'allowed_types' => 'jpg|jpeg|png|gif',
        'upload_path' => path/to/folder,
        'max_size' => 3000,
        'max_height' => 1024,
        'max_width' => 1024,
        'remove_spaces' => TRUE
    );
    $this->load->library('upload', $config);

    if ($this->upload->do_upload())
    {
        //code for insert this data into database
    }
    else
    {
        //code for FALSE the form validation and error message with flashdata
    }
现在我想假形式,如果有一些错误与图像上传。我想这样做,就像某个字段的错误一样,如果它是空的,则获取字段内容的post变量数据

最好的方法是什么

$this->form\u validation->run和$this->upload->do\u upload的else条件应该类似

表单验证:

$data['error_message'] = validation_errors();
$this->load->view('form', $data);
文件上载:

$data['error_message'] = $this->upload->display_errors();
$this->load->view('form', $data);
“表单”视图是最初加载的视图。它可以有这样一个div:

<div class="error_message">
   <?php if ($error_message) {
      echo $error_message;
   } ?>
</div>

我知道,但我不是在问这个。我正在寻找一种解决方案,如果上传文件有什么不好的地方,它只会错误地执行表单验证。示例:如果$uploaderror==TRUE{return false;//false表单验证并返回所有字段值}再次加载表单,就像我在回复中提到的那样,应该这样做。如果要重新填充字段,只需在每个字段上使用set_value函数。if$this->upload->do_upload的else条件与$uploaderror==true完全相同。您的答案是正确的,问题出在我这边。我使用了一些不同的set_值,我没有考虑它。再次感谢。还有一个问题。。。如果表单的字段出现错误,此路径将消失,是否可以为表单上传获取一些函数,如set_value?出于安全原因,您无法在用户计算机上保存图像的路径。但是,您可以在验证整个表单之前执行上载,如下所示:如果$this->upload->do_upload&&$this->form_validation->run==TRUE,或者您可以在表单验证的回调函数中执行此操作。阅读更多: