CF8 - Text Area - Badword Filter - JSON.parse

rbock 19 Oct, 2023
Hello Max...

For public text fields I use the Valid function and the following as a PHP script:

#########################################################

$p1 = file_get_contents('bad.txt');
$p2 = preg_split("#\r?\n#", $p1, -1, PREG_SPLIT_NO_EMPTY);
$p3 = "~\b(". implode('|', $p2) . ")\b~i";

if(preg_match($p3, $value)) {return error;}

return true;

#########################################################

This also works, but throws a Json.parse error in the console.
Max_admin 20 Oct, 2023
what is the "error" in the code ? the PHP should return a string (error message) or TRUE
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
rbock 20 Oct, 2023
Sorry:

-> return "Hier stimmt etwas nicht... Bitte prüfen!";

not

return error;
rbock 20 Oct, 2023
Uncaught SyntaxError: JSON.parse: unterminated string at line 1 column 77 of the JSON data
rbock 20 Oct, 2023
I think the worm is in here:

$p3 = "~\b(". implode('|', $p2) . ")\b~i";
rbock 20 Oct, 2023
Error found... Apparently ' is causing problems... But no problem, I adjust the line and rearrange the text file so that the words are not line by line but with | are separated. So I need '|' no longer.
You need to login to be able to post a reply.