Colored Validation

nassausky

Member
[pre]
You are using DaDaBIK version 6.2 ENTERPRISE
You are runnning the last release of DaDaBIK
PHP Version: 5.3.29
mysql version: 5.5.32-31.0-log
Web server: Apache
Client: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36
[/pre]

I got custom_functions to validate a field but does anyone have any ideas on how to get validation to highlight the field in red when it is incorrectly entered?

Thanks again,
 

nassausky

Member
OK I got it.

Heavy digging and I got it to highlight a field which doesn't pass validation and on top of that I also made it so that it jumps to the field which doesn't pass validation (which is now colored red).

Probably other ways to do it but this is how I did it.
I created a new table called dadabik_errors with a single field called validation_error (possibly there is a way to do it in sessions)


In business_logic.php: Changed below to make the edit form update submission include an anchor I put on the field which doesn't validate:
[pre]
$form .= "<form class=\"css_form\" id=\"dadabik_main_form\" name=\"contacts_form\" method=\"post\" action=\"".$action."?table_name=".urlencode($table_name)."&function=".$function.$form_querystring_temp."\" enctype=\"multipart/form-data\">\n";
[/pre]
to
[pre]
$form .= "<form class=\"css_form\" id=\"dadabik_main_form\" name=\"contacts_form\" method=\"post\" action=\"".$action."?table_name=".urlencode($table_name)."&function=".$function.$form_querystring_temp."#error_anchor\" enctype=\"multipart/form-data\">\n";
[/pre]

In business_logic.php:Changed below to highlight hint area red if record in dadabik_errors matches the current row:
[pre]
$form .= "<td class=\"td_hint_form\" style=\"background:red;\">  ".$fields_labels_ar[$i]["hint_insert_field"]."<a name=\"error_anchor\">*</a></td>"; // display the insert hint if it's the insert form
[/pre]
to
[pre]
$sql = "SELECT validation_error FROM dadabik_errors";
$res = execute_db($sql, $conn);
$result=$res->fetch(PDO::FETCH_ASSOC);
if ($result['validation_error'] === $fields_labels_ar[$i]["name_field"]){
$form .= "<td class=\"td_hint_form\" style=\"background:red;\">  ".$fields_labels_ar[$i]["hint_insert_field"]."<a name=\"error_anchor\">*</a></td>"; // display the insert hint if it's the insert form
}
else{
$form .= "<td class=\"td_hint_form\">  ".$fields_labels_ar[$i]["hint_insert_field"]."</td>"; // display the insert hint if it's the insert form
}
[/pre]
In business_logic.php in the function check_fields_types changed below:
[pre]
global $year_field_suffix, $month_field_suffix, $day_field_suffix, $null_checkbox_prefix, $field_type_for_date;
[/pre]
to
[pre]
global $conn, $year_field_suffix, $month_field_suffix, $day_field_suffix, $null_checkbox_prefix, $field_type_for_date;
[/pre]
and in that same function below changed:
[pre]
if ($check === false){
$check = 0;
$content_error_type = $fields_labels_ar[$i]["custom_validation_function_field"];
}
[/pre]
to
[pre]
if ($check === false){
$check = 0;
$content_error_type = $fields_labels_ar[$i]["custom_validation_function_field"];
$validation_error_field=$field_name_temp;
$sql = "INSERT INTO dadabik_errors (validation_error) VALUES('".$validation_error_field."')";
$res = execute_db($sql, $conn);
}
else
{
$sql="DELETE FROM dadabik_errors";
$res = execute_db($sql,$conn);
}
[/pre]

In index.php: Changed below to clear out dadabik_errors table on returning to the search screen
[pre]
case "search":
[/pre]
to
[pre]
case "search":
$res = execute_db("DELETE FROM dadabik_errors",$conn);
[/pre]

And I think that was it. I hope that helps someone and maybe in the next version we can get that added hehe :)
 
Top