* Optimize the code.

This commit is contained in:
qiyu-xie
2020-12-11 16:17:18 +08:00
parent 9efabc5d05
commit feb8e765ae
+17 -11
View File
@@ -1237,18 +1237,24 @@ class programModel extends model
}
}
/* When select create new product, product name cannot be empty. */
if(isset($_POST['newProduct']) and empty($_POST['productName']))
/* When select create new product, product name cannot be empty and duplicate. */
if(isset($_POST['newProduct']))
{
dao::$errors[] = sprintf($this->lang->error->notempty, $this->app->loadLang('product')->product->name);
return false;
}
$existProductName = $this->dao->select('name')->from(TABLE_PRODUCT)->where('name')->eq($_POST['productName'])->fetch('name');
if(!empty($existProductName))
{
dao::$errors[] = $this->lang->program->existProductName;
return false;
if(empty($_POST['productName']))
{
$this->app->loadLang('product');
dao::$errors[] = sprintf($this->lang->error->notempty, $this->lang->product->name);
return false;
}
else
{
$existProductName = $this->dao->select('name')->from(TABLE_PRODUCT)->where('name')->eq($_POST['productName'])->fetch('name');
if(!empty($existProductName))
{
dao::$errors[] = $this->lang->program->existProductName;
return false;
}
}
}
$requiredFields = $this->config->program->PRJCreate->requiredFields;