Callback to execute a script upon Save
Callback to execute a script upon Save

I'm not sure what exactly it is called, but I use the term callback. I'm using datatables editor to manage a list of articles, add/edit/delete. With each article there will be an alias or URL. In the popup editor when adding a new page or article I have the title, publish and a few other items including this alias field.
Rather than relying on the human administrator to enter a people-friendly alias I would like to execute a script/function upon save that will create the alias, something like:
setlocale(LC_ALL, 'en_US.UTF8');
function toAscii($str, $replace=array(), $delimiter='-') {
if( !empty($replace) ) { $str = str_replace((array)$replace, ' ', $str); }
$data = iconv('UTF-8', 'ASCII//TRANSLIT', $str);
$data = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $data);
$data = strtolower(trim($data, '-'));
$data = preg_replace("/[\/_|+ -]+/", $delimiter, $data);
$data = strtolower(trim($data, '-'));
return $data;
}
To use it in a non-datatables script:
$alias = ($mysqli->real_escape_string($_POST["alias"]));
$alias = toAscii($alias);
Can this be done, how?
Answers
Hi @koniahin ,
You could use the server-side events such as
preEdit
andpreCreate
, as shown in this example here.Hopefully that'll do the trick, but shout back if not,
Cheers,
Colin