Hello guys,
I don't know if it's a bug or not, so hopefully someone will find out ;-)
So on my xcrud form I have a function that checks data validity. Of course it needs to be called both on inserts and updates, so it's called like that:
The function itself is located in xcrud's functions.php file:
Now comes the really weird (or maybe buggy) part :
- During the initial insert, it works perfectly...
- But if you edit an originally valid entry to add some invalid entry and save again, the following error message is displayed:
Anyone has an idea of what is going on here? I've tried tons of variations but still get this error.
I totally don't get why it works on the initial insert and not after entry update...
Thanks a lot,
I don't know if it's a bug or not, so hopefully someone will find out ;-)
So on my xcrud form I have a function that checks data validity. Of course it needs to be called both on inserts and updates, so it's called like that:
PHP:
$xcrud->before_insert('verify_departements_csv');
$xcrud->before_update('verify_departements_csv');
The function itself is located in xcrud's functions.php file:
PHP:
function verify_departements_csv($postdata, $xcrud){
$dept_csv_error = FALSE;
$depts_csv = $postdata->get('depts_csv_for_type');
$depts_csv_array = explode(",", $depts_csv);
foreach ($depts_csv_array as $dept_code) {
if ( strlen($dept_code)<2 || !is_numeric($dept_code) || empty($dept_code) || is_null($dept_code) ) {
$dept_csv_error = TRUE;
break;
}
}
if(str_contains($depts_csv, ',,')){
$dept_csv_error = TRUE;
}
if ($dept_csv_error) {
$xcrud->set_exception('depts_csv_for_type','Error in Syntax of CSV departements list!');
}
}
Now comes the really weird (or maybe buggy) part :
- During the initial insert, it works perfectly...
- But if you edit an originally valid entry to add some invalid entry and save again, the following error message is displayed:
Fatal error: Uncaught Error: Call to a member function set_exception() on string in /home/user76567/public_html/xcrud/dashx/xcrud/functions.php:95 Stack trace: #0 /home/user76567/public_html/xcrud/dashx/xcrud/xcrud.php(3709): verify_departements_csv(Object(Xcrud_postdata), '14', Object(Xcrud)) #1 /home/user76567/public_html/xcrud/dashx/xcrud/xcrud.php(2017): Xcrud->_save() #2 /home/user76567/public_html/xcrud/dashx/xcrud/xcrud.php(1984): Xcrud->_run_task() #3 /home/user76567/public_html/xcrud/dashx/xcrud/xcrud.php(368): Xcrud->render() #4 /home/user76567/public_html/xcrud/dashx/xcrud/xcrud_ajax.php(3): Xcrud::get_requested_instance() #5 {main} thrown in /home/user76567/public_html/xcrud/dashx/xcrud/functions.php on line 95
Anyone has an idea of what is going on here? I've tried tons of variations but still get this error.
I totally don't get why it works on the initial insert and not after entry update...
Thanks a lot,