首页 > 解决方案 > 多文件输入和表单验证?

问题描述

我的表单中有多个文件和输入文本。我的代码是:

if(formValidationIsGood) {
   if(customeCheckFileErrorIsEmpty) {
      //StartProcess
   }
   else {
    //I load my view with my array which contains the different error related to the files.
   }
else {
    //I load my view with the form error (set up by : $this->form_validation->set_rules('variable', 'Variable', 'required');) But if there is an error for the files I cant display it.
}

使用此代码,我无法同时显示表单错误和文件错误。例如,用户正在上传 csv 文件而不是 pdf 文件,并且他忘记写入文本输入,将显示表单错误但不会显示文件错误,反之亦然。
显然我正在使用代码点火器提供的帮助文件。

标签: phpcodeigniter

解决方案


由于您想显示 A 或 B 的错误消息,您可以试试这个:

if (!formValidationIsGood || !customeCheckFileErrorIsEmpty)
{
  // load the view and display whatever errors you found
}

else
{
  // form validation IS good and the files error is empty
}

上面的if子句将评估true是否formValidationIsGoodISN'T true!前缀是关键)或customeCheckFileErrorIsEmptyISN't true(这意味着存在错误)


推荐阅读