Need a simple text dropdown that returns an int

Hello,

Maybe I am missing something totally simple here on the form configurator.

I am trying to have my select single field dropdown for a digital field have values of YES/NO but save the data as a 1 or 0 int in a tinyint size 1 DB field.
I have tried using the hardcoded list of options (ie. ~YES~NO~) and the following custom formatting functions.
[pre]
function dadabik_yes_no_to_tinyint1($value){
if ($value == "YES")
{return '1';}
else
{return '0';}
}

function dadabik_yes_no_to_tinyint2($value){
if ($value == "YES")
{return 1;}
else
{return 0;}
}
[/pre]

But none of these options work. I usually get database errors writing the wrong type for the field so the custom func is probably not working. I could do a hardcoded list of "~1~0~" but then I will have to convert a lot of incoming data and users will complain.

I would really like to avoid creating a database table to create such a simple drop down.What is the best practice for accomplishing this? Do you have any suggestions?

Thanks in advance.
 

JDonovan

New member
I am trying to to the same thing! Offer up a Yes/No (or a checkbox?) but save to DB as 1 or 0. Thanks in advance...
 
Sorry, I didn't get the support details in in time for my prior post ...

[pre]
Your current DaDaBIK version
You are using DaDaBIK version 10.1-Manarola enterprise, installed on 05-20-2020 (installation code: 155575ec56a3af068e), the latest version of DaDaBIK is 10.1-Manarola released on 03-09-2020

You are runnning the last release of DaDaBIK

System info
PHP Version: 7.2.5

mysql version: 5.5.5-10.2.31-MariaDB

Web server: Apache

Client: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36
[/pre]
 

eugenio

Administrator
Staff member
Hello,
at the moment the best practice is to use a lookup field and a yes/no table, you can have one yes/no table and keep it for all the yes/no fields of your project.
I agree we should have a built-in yes/no field type though ...

Best,
 
Top