Forums

Db don't save zero value of radiobox

gcanavate 07 Feb, 2016
Hi,
I have a radiobox like
0=0
1=1
2=2
3=3
But, when I submit and read de DB, the zero values are in blank, but not the other values. How can i do, to force "0" in DB when the value is zero? and not blank
It's very important for me, because i've to reconvert de blank fields in "0" after and it's very bad.

thanks
GreyHead 07 Feb, 2016
Hi gcanavate,

What are the Radio buttons for? I advise that you don't use 0 as a value because of this problem. Can you use zero=0 ?

Bob
gcanavate 08 Feb, 2016
Hi, I 'm using a Likert scale in which the user must choose the values ​​of the scale ( from 0 to 6 according to a predetermined scale : strongly disagree to strongly agree) .
I need the number "0" is recorded for calculations. The question is, that the remaining numbers (from 1 if they are recorded , but not zero )
GreyHead 08 Feb, 2016
Hi gcanavate,

Hmmm . . . Please try this. Set the option as I suggested to zero=0, then in the On Submit event add a Custom Code action before the DB Save with some code like this
<?phop
if ( $form->data['radio_name'] == 'zero' ) {
  $form->data['radio_name'] = 0;
}
?>
and replace radio_name with the name of your Radio Button element.

Bob

[[>> later - updated to fix typos <<]]
gcanavate 08 Feb, 2016
It doesn't works, i'm sorry.

With your code and with another code like this:

<?php
If ( $form->data['p1'] = = 'zero' ) {
$form->data['p1'] = 0;
}
?>

The result is Blank (no data) in the DB.
Some another solution?
GreyHead 08 Feb, 2016
Hi gcanavate,

What is the type of the column you are saving to in the database?

Bob
gcanavate 08 Feb, 2016
Normally i'm using TEXT, because my table has 220 variables (too long table), but in this case i'm using VARCHAR (the default value).

Maybe, is better to use BOOL?
GreyHead 08 Feb, 2016
Hi gcanavate,

Please try INT or TINYINT

BOOL will only allow 0 or 1 and you need 0-6

Bob
gcanavate 08 Feb, 2016
does not work. I've tried with INT and TINYINT and don't save "0" value.
German
GreyHead 08 Feb, 2016
Hi gcanavate,

Apologies, there were some typos in the code I posted, please check the updated version.

Bob
gcanavate 08 Feb, 2016
No, It doesn't work.
<?php
if ( $form->data['p1'] == 'zero' ) {
  $form->data['p1'] = 0;
}
?>
GreyHead 08 Feb, 2016
Hi gcanavate,

By all means PM me the site URL, the form name, and a SuperAdmin login and I'll take a quick look.

Bob
Max_admin 08 Feb, 2016
A VARCHAR with length "3" for example should work, did you try that ? this should store any value passed.

You may also try INT, length 2, default 0

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
GreyHead 09 Feb, 2016
Hi gcavanate,

I took a look at the form and used the Table Backup icon to see the data saved, It looks as though the '0's are being saved correctly - it's just that the Data Viewer doesn't display them correctly,

Bob
gcanavate 09 Feb, 2016
thank you very much for the interest you have shown. You have been very helpful.
This topic is locked and no more replies can be posted.