Error hint in form

Hi Eugenio,
when I leave a required field empty inside of a form, there is a common error message shown on top of the form. But neither do the appropriate fields get a particular class, nor is there an error label shown next to them. This makes it pretty hard for people to determine what went wrong in a large form.
Did I oversee something, for example to activate the error message behaviour?

Best Wishes
Andreas

You are using DaDaBIK version 8.2-Lerici enterprise, installed on 01-14-2018 (installation code: 132625a5b34516cf0a), the latest version of DaDaBIK is 8.2-Lerici released on 12-19-2017
You are runnning the last release of DaDaBIK
PHP Version: 7.0.25
mysql version: 5.7.20
Web server: Apache/2.4.29 (Unix) PHP/7.0.25
Client: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:59.0) Gecko/20100101 Firefox/59.0
 

eugenio

Administrator
Staff member
Hello Andreas,
it's something we really want to improve (at least adding a class to the missing fields) but at the moment it works exactly as you describe.
You can personalize the message if the field has a custom required function, though.

Best,
 
Hi Eugenio,
thank you for your reply, that's unfortunate.
I will give it a try with defining custom required functions but that will be a lot of work because we have a large amount of fields :[

Best wishes
Andreas
 
Hi Eugenio,
I don't understand how a custom error message can be established with the help of a custom required function. Could you give me hint? As mentioned earlier my form has a lot of fields that are required so there are multiple individual error messages necessary.

Thanks in advance
Andreas
 

eugenio

Administrator
Staff member
Hello,
sorry I said custom required function but I meant custom VALIDATION function.

Something like:

function dadabik_validate_first_name($parameters_ar)
{
if ($parameters_ar['first_name'] === ''){
return false;
}
else{
return true;
}
}

and then you have to write the message in english_custom.php:
$normal_messages_ar['dadabik_validate_first_name_not_valid'] = 'The first name is required.';

I've realized, however, that this approach has a problem: the validation function is called ONLY if the field is not empty so you should also change this line in the core code (business_logic.php file):

from
if (($fields_labels_ar[$i]["type_field"] == "text" || $fields_labels_ar[$i]["type_field"] == "textarea" || $fields_labels_ar[$i]["type_field"] == "date" || $fields_labels_ar[$i]["type_field"] == "rich_editor" || $fields_labels_ar[$i]["type_field"] == "date_time") and $field_to_check == "1" and $_POST_2[$field_name_temp] != ""){

to

if (($fields_labels_ar[$i]["type_field"] == "text" || $fields_labels_ar[$i]["type_field"] == "textarea" || $fields_labels_ar[$i]["type_field"] == "date" || $fields_labels_ar[$i]["type_field"] == "rich_editor" || $fields_labels_ar[$i]["type_field"] == "date_time") and $field_to_check == "1"){

which means that, for all fields, the validation function (if any) will be called even if the field is empty. Don't know if this change, in your case, can lead to problems.

Best,
 
Hi Eugenio,

thanks for your reply, but this is not working in my case:

custom_functions.php:
function dadabik_validate_vorname($parameters_ar) {
if ($parameters_ar['vorname'] === '') {
return false;
}
else {
return true;
}
}

german_custom.php
$normal_messages_ar['dadabik_validate_vorname_not_valid'] = 'Bitte geben Sie einen Vornamen an!';

Forms configurator, field "vorname"
Field type: text
Content type: alphanumeric
Custom validation function: dadabik_validate_vorname

Also I changed business_logic.php as proposed.
Could you give me a hint?

Best wishes
Andreas
 

eugenio

Administrator
Staff member
Everything seems correct, what happens exactly? Do you see any error?

Try to add these two lines

var_dump($parameters_ar['vorname']);
die('test');

after:

function dadabik_validate_vorname($parameters_ar) {

what happens now?
 

eugenio

Administrator
Staff member
Probably this is happening because the field is stil set as "required", is it? Try to set it as not required.
 
OK, obviously there are the following prelimitations to make this work:

1. All the other required fields have to be filled correctly

2. The field itself is not set as required

conclusion: I have to define custom validation functions for all required fields and have to add the asterisks in the labels.
It would be really great if you could realize an error message workflow soon!

Thanks for your help.
 

eugenio

Administrator
Staff member
We'll improve it in DaDaBIK 9, still don't know how exactly: I am not completely sure about providing single error messages for required fields, if the form is very long it could be annoying.
How would the perfect solution look like for you?

Best,
 
Top