Validate the form

FRW

Well-known member
Hi, just a few questions about validating the form:

1.- is it possible to do more than one validation (written in custom_validation_functions.php) with different error_messages?

2.- can I use the $error_messages_ar[] for js-events?

Thanks and stay healthy!
 

eugenio

Administrator
Staff member
Hello,

1) Do you mean more than one validation for the same field? I don't understand. The validation error message is just one for each field.

2) No, the messages in the language files can be used for the PHP custom functions only

Best,
 

FRW

Well-known member
1) yes, I ment different validations for the same field.
F.e.: If the input is text, error message= "Pleas only numbers!",
if the input fails the duplicate check, error message= "There is still an entry of this"

But I thought it won't work, thanks.
 

eugenio

Administrator
Staff member
Oh I see; no, at the moment it is not possible, normally in these cases i create a unique message containing all the possible reasons (e.g. the field contains letters or there is a duplication ...), but yes, I agree that in some cases this might be not very user friendly.

Best,
 

FRW

Well-known member
Maybe the future will solve this ;-)

btw.: How to check the value (here: empty) of another field within an JS-Event?
 

eugenio

Administrator
Staff member
FRW Wrote:
-------------------------------------------------------
> Maybe the future will solve this ;-)

Yes, adding multiple error messages to the same validation could be useful.

> btw.: How to check the value (here: empty) of anot
> her field within an JS-Event?

There isn't any built-in special way, I would check the name of the field and use it, with jquery or plain javascript, to check the content of the field. This is not integrated with the DaDaBIK validation though, so you should handle your own messages/alerts.

Best,
 

FRW

Well-known member
maybe useful for others:

FieldA must contain something before entering FieldB and FieldB has to be a number. Done this for FieldB with:
[pre]
function dadabik_FieldB(field)
{
if($('input[name="FieldA"]')[0].value == ""){
alert('Bitte zuerst BestMa-ID eingeben');
$('input[name="FieldA"]').focus();
} else if(isNaN(field.value)){
alert('Bitte als maximal 4-stellige Zahl eingeben');
$('input[name="FieldB"]').focus();
}
}
[/pre]
 
Top