This topic is locked

Where and how to add custom client side validation?

2/11/2022 3:54:27 AM
PHPRunner General questions
M
mdfaisalpapa author

I need to validate the form before insert/edit . Where and how to validate the data in the form?

K
kohle 2/11/2022

Hi,

go to the tabfolder events , than to the add page and there to the
"before add" event.
For the edit page goto the event "before record updated"

Here you write your validation code, ex.

if your validation dont pass then return :

$message= "Your error message";
return false;

Examples of my code :

if($values['Personal_Nr'] != 0 && $values['flg_fremd'] == 1 ){
$message = "Datensatz enthält eine Personal Nr. und kann nicht als Fremdfirma deklariert werden.";
return false;
}
return true;

or

Add page in "before add" event : I Check if Social no. already exists in table data.

$sql2 = "SELECT count(*) FROM t_emp_user_zusatz WHERE Sozialversicherungsnr = '" . $values['Sozialversicherungsnr'] . "'" ;
$count = DBlookup($sql2);

//if Sozialversicherungsnr exists
if($count > 0){
$message = 'Sozialversicherungsnr ' . $data2['Sozialversicherungsnr'] . ' existiert schon. [Mitarbeiter: ' . $data2['Name'] . ', ' . $data2['Vorname'] . ']';
return false;
}

.....
.....

return true;

rgs.
J.

M
mdfaisalpapa author 2/12/2022

The above solution is server side validation. I need client side validation using Javascript.

Sergey Kornilov admin 2/16/2022

There are multiple options to do so. You can use field events to check individual field values. You can also check beforeSave Javascript event.