Boolean type

nassausky

Member
I have a MySQL database with a field type I setup as Boolean which gets automatically set to TinyInt(1). How do I setup the Form Configurator to allow someone to choose either Yes or No and have it automatically add it to the database as either a 1 or 0? I was hoping it was easy with a simple setup in Forms Configurator.

Any help would be great.

Thanks.
 

nassausky

Member
Got it thanks to an ancient post from mouloud:

The following code is updated for dadabik 6.2
Had to make a change to 2 files:

internal_table.php line 33:

[pre]
$int_fields_ar[$ar_index][3] = "Text fields~text/textarea/rich_editor/Date and time fields~date/date_time/insert_date/update_date/List fields~select_single/select_multiple_menu/select_multiple_checkbox/File fields~generic_file/image_file/Other~ID_user/unique_ID/boolean";//Note Boolean added to end parameter
[/pre]






business_logic.php line 2412
[pre]
case "boolean": //Remember to add boolean to file /incude/internal_table.php line 33
$form .= "<td class=\"td_input_form\">".$select_type_select; // first part of the second coloumn of the form
$field_temp = substr($fields_labels_ar[$i]["select_options_field"], 1, -1); // delete the first and the last separator
if (trim($field_temp) !== '') {
$select_values_ar = explode($fields_labels_ar[$i]["separator_field"],$field_temp);
} else {
$select_values_ar = array("yes", "no" );
}
$checked = "" ;
if ($form_type === 'update' or $form_type === 'ext_update') {
if ($show_edit_form_after_error === 1) {
if (isset($_POST[$field_name_temp]) && 1 == stripslashes($_POST[$field_name_temp])) {
$checked = " checked";
} // end if
} // end if
else {
if (1 == $details_row[$field_name_temp]) {
$checked = " checked";
} // end if
} // end else
} // end if
if ($form_type === 'insert' && $show_insert_form_after_error === 1 && isset($_POST[$field_name_temp]) && 1 == stripslashes($_POST[$field_name_temp])){
$checked = " checked";
} // end if
$form .= "<input type=\"radio\" name=\"".$field_name_temp."\" value=\"1\"" . $checked . ">" . $select_values_ar[0] ;
$checked = "" ;
if ($form_type === 'update' or $form_type === 'ext_update') {
if ($show_edit_form_after_error === 1) {
if (isset($_POST[$field_name_temp]) && 0 == stripslashes($_POST[$field_name_temp])) {
$checked = " checked";
} // end if
} // end if
else {
if (0 == $details_row[$field_name_temp]) {
$checked = " checked";
} // end if
} // end else
} // end if
if ($form_type === 'insert' && $show_insert_form_after_error === 1 && isset($_POST[$field_name_temp]) && 0 == stripslashes($_POST[$field_name_temp])){
$checked = " checked";
} // end if
$form .= "<input type=\"radio\" name=\"".$field_name_temp."\" value=\"0\"" . $checked . ">" . $select_values_ar[1] ;
$form .= "</td>\n"; // last part of the second coloumn of the form
break ;
[/pre]
 

eugenio

Administrator
Staff member
Hello,
a safer option (I haven't tested the code above s oI am not sure if it is OK and for which version) would be to have a yes-no table containing just two records
0 no
1 yes
and use in form configurator a normal select_single field type pointing to that table.
 

nassausky

Member
Thanks I was thinking about that.

2 reasons I wanted it the way I did it.

1) It uses the radio button selection which is faster to choose

2) I think it's simpler in the long run to not have to create tables for every boolean I decide to make.

Thanks again.
 

eugenio

Administrator
Staff member
You are right, boolean fields are easy to use for this kind of situation and we will add them in a future release of DaDaBIK.
About the additional table, however, you don't have to create a new one for each field. Just one yes/no table is enough.
 
Top