Page 1 of 1
Save the value of a checkbox
Posted: Sun Sep 05, 2021 8:10 am
by Somayeh
Hi guys. I defined a checkbox in my form and get it with @= in a trigger , also I defined it boolean in database , but in database I always see 0 or zero , when it checked or unchecekd . How can I solve my problem?
Re: Save the value of a checkbox
Posted: Sun Sep 05, 2021 8:25 pm
by kirkwg
Hi, Mind to show some codes on how you did for that checkbox, as more easy for me to help troubleshoot thanks
Re: Save the value of a checkbox
Posted: Mon Sep 06, 2021 4:03 am
by Somayeh
Hi , i define a boolean variable in my form. its name is chkxstatusAks , then i define a trigger:
$db='5552845836131e996ab9677075960874';
$chkxstatusAks = @=chkxstatusAks;
$query = "INSERT INTO `eaa` (`Id`, `chkxstatusAks`)VALUES (NULL,'$chkxstatusAks');";
$result = executeQuery($query,$db);
and i created a table by the name of eaa in database and a column for chkxstatusAks and its type is BOOLEAN . and when i run my process, my checkbox(chkxstatusAks) always saves 0 in db , checked or unchecked.
Re: Save the value of a checkbox
Posted: Mon Sep 06, 2021 4:25 am
by kirkwg
Hi
You can't directly accessing the checkbox with @=, you need to check its value?
docs link: https://wiki.processmaker.com/3.1/Checkbox_and_Checkbox_Group#Accessing_a%20Checkbox_with_PHP
Try the trigger php code:
Code: Select all//if checkbox is marked:
if (isset(@=chkxstatusAks) and @=chkxstatusAks == array(1)) {
$chkxstatusAks = 1;
}
else { //if unmarked:
$chkxstatusAks = 0;
}
$query = "INSERT INTO `eaa` (`Id`, `chkxstatusAks`)VALUES (NULL,'$chkxstatusAks');";
$result = executeQuery($query,$db);
Try and see, thanks.
Re: Save the value of a checkbox
Posted: Mon Sep 06, 2021 5:54 am
by Somayeh
Thank you so much. my problem was solved.