Check if an required extrafield is filled.
Method setOptionalsFromPost now return -1 if required field is blank
This commit is contained in:
parent
0dc7aa15d9
commit
c431fc716f
@ -677,28 +677,28 @@ class ExtraFields
|
||||
}
|
||||
elseif ($type == 'sellist')
|
||||
{
|
||||
|
||||
|
||||
$out='<select class="flat" name="options_'.$key.'">';
|
||||
if (is_array($param['options'])) {
|
||||
$param_list=array_keys($param['options']);
|
||||
$InfoFieldList = explode(":", $param_list[0]);
|
||||
|
||||
|
||||
// 0 1 : tableName
|
||||
// 1 2 : label field name Nom du champ contenant le libelle
|
||||
// 2 3 : key fields name (if differ of rowid)
|
||||
|
||||
|
||||
$keyList='rowid';
|
||||
|
||||
|
||||
if (count($InfoFieldList)==3)
|
||||
$keyList=$InfoFieldList[2].' as rowid';
|
||||
|
||||
|
||||
$sql = 'SELECT '.$keyList.', '.$InfoFieldList[1];
|
||||
$sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[0];
|
||||
//$sql.= ' WHERE entity = '.$conf->entity;
|
||||
|
||||
|
||||
dol_syslog(get_class($this).'::showInputField type=sellist sql='.$sql);
|
||||
$resql = $this->db->query($sql);
|
||||
|
||||
|
||||
if ($resql)
|
||||
{
|
||||
$out.='<option value="0"> </option>';
|
||||
@ -833,8 +833,8 @@ class ExtraFields
|
||||
$keyList='rowid';
|
||||
if (count($InfoFieldList)==3)
|
||||
$keyList=$InfoFieldList[2];
|
||||
|
||||
|
||||
|
||||
|
||||
$sql = 'SELECT '.$InfoFieldList[1];
|
||||
$sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[0];
|
||||
$sql.= ' WHERE '.$keyList.'=\''.$this->db->escape($value).'\'';
|
||||
@ -894,7 +894,9 @@ class ExtraFields
|
||||
*/
|
||||
function setOptionalsFromPost($extralabels,&$object)
|
||||
{
|
||||
global $_POST;
|
||||
global $_POST, $langs;
|
||||
$nofillrequired='';// For error when required field left blank
|
||||
$error_field_required = array();
|
||||
|
||||
if (is_array($extralabels))
|
||||
{
|
||||
@ -903,6 +905,12 @@ class ExtraFields
|
||||
{
|
||||
$key_type = $this->attribute_type[$key];
|
||||
|
||||
if($this->attribute_required[$key] && !GETPOST($value))
|
||||
{
|
||||
$nofillrequired++;
|
||||
$error_field_required[] = $value;
|
||||
}
|
||||
|
||||
if (in_array($key_type,array('date','datetime')))
|
||||
{
|
||||
// Clean parameters
|
||||
@ -929,7 +937,14 @@ class ExtraFields
|
||||
$object->array_options["options_".$key]=$value_key;
|
||||
}
|
||||
|
||||
return 1;
|
||||
if($nofillrequired) {
|
||||
$langs->load('errors');
|
||||
setEventMessage($langs->trans('ErrorFieldsRequired').' : '.implode(', ',$error_field_required),'errors');
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user