Hello,
I have a table with a field called "approved" managed with a checkbox and I want that a record (after created or modified) can be saved only if that checkbox is checked.
Is this achievable using "before insert" / "before_update" function in the hook ?
ALex.
Save record only if a checkbox is checked.
Re: Save record only if a checkbox is checked.
This works for me if I set the checkbox to required.
Re: Save record only if a checkbox is checked.
Ok this is a walkaround, but is there a method to check the status of a checkbox (selected/not selected) before save a record in the hook, possibily not have to use Javsacript ?
ALex.
ALex.
Re: Save record only if a checkbox is checked.
Hi there,
I use code like this in before_update function
Have a nice day.
I use code like this in before_update function
Code: Select all
function TABLENAME_before_update(&$data, $memberInfo, &$args) {
// if checkbox_field is not checked, don't allow updating it
if ($data['checkbox_field'] <> 1) {
$args['error_message'] = 'Your error message.';
return false;
};
}
return TRUE;
Zala.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.
Re: Save record only if a checkbox is checked.
Thank you a LOT zibrahim !!!
ALex.
ALex.
Re: Save record only if a checkbox is checked.
Hi ALex,
Glad it helped. However, I just realised that I have made a mistake in the code.
the return TRUE; statement should be inside the before_insert function (curly bracket), not outside.
It should be like this.
Apologise for my mistake. Have a nice day.
Glad it helped. However, I just realised that I have made a mistake in the code.
the return TRUE; statement should be inside the before_insert function (curly bracket), not outside.
It should be like this.
Code: Select all
function TABLENAME_before_update(&$data, $memberInfo, &$args) {
// if checkbox_field is not checked, don't allow updating it
if ($data['checkbox_field'] <> 1) {
$args['error_message'] = 'Your error message.';
return false;
};
return TRUE;
}
Zala.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.
Re: Save record only if a checkbox is checked.
thanks a lot