This topic is locked

How to set Checkbox values?

8/30/2006 5:53:09 AM
PHPRunner General questions
K
kneighbour author

I have just fired up the beta 3.1 and it is a lot more impressive than 3.0. A big difference. It seems to be a bit better than 3.0 as well (less bugs).
I did wonder how to set the Checkbox values? ie how do you set what value in a field sets it checked and unchecked?
It seems to be hardwired to 0=unchecked and 1=checked. This is certainly not much good if it is the case.

J
Jane 8/30/2006

Hi,
you can select Checkbox on the "View as" settings and "Edit as" settings dialogs on the Visual editor tab.

T
thesofa 8/30/2006

I have just fired up the beta 3.1 and it is a lot more impressive than 3.0. A big difference. It seems to be a bit better than 3.0 as well (less bugs).

I did wonder how to set the Checkbox values? ie how do you set what value in a field sets it checked and unchecked?
It seems to be hardwired to 0=unchecked and 1=checked. This is certainly not much good if it is the case.



Are you trying to get the values saved as "Y" or "N", or "M" or "F" for example, rather than 0 or1?

K
kneighbour author 8/30/2006

Are you trying to get the values saved as "Y" or "N", or "M" or "F" for example, rather than 0 or1?



Well, in this case I am trying to set 1=unchecked and 0=checked, but it could be anything, as you suggest.

F
fullfusion 9/25/2006



Well, in this case I am trying to set 1=unchecked and 0=checked, but it could be anything, as you suggest.


Hello,
I am a newbie and was wondering if you have a recepie as to how to change the values so they will show up as "Y" and "N" in my database (instead of 1 and 0).
Thank you in advance!

mikue from germany 9/25/2006

Hi,
maybe this is a solution for someone, edit SQL-Tab like this:
select `ID`,`yes_no_field`,

if (yes_no_field=1,'Y','N') as YN_field,

From `table`
Define in Add & Edit a Checkbox, display the yes_no_field ;

define in List & View a textfield, display the YN_field.
Important is always to name a Y/N field clearly i.e. (IsOccupied, IsNormal, IsTrue)
Greetings from Germany, mikue

Sergey Kornilov admin 9/25/2006

You can use BeforeEdit event for this purpose.
Something like this will work:
function BeforeEdit(&$values, $where)

{
if ($values["Model"]=="1")

$values["Model"]="Y";

else

$values["Model"]="N";
return true;
}
This will write 'Y' and 'N' to the database instead of 1 and 0.
The only problem is that checkbox control won't recognize 'Y' and 'N' as a valid input.

Probably you can modify SQL query to convert Y and N back to 1 and 0 so checkboxes work fine.

F
fullfusion 9/26/2006

You can use BeforeEdit event for this purpose.

Something like this will work:
function BeforeEdit(&$values, $where)

{
if ($values["Model"]=="1")

$values["Model"]="Y";

else

$values["Model"]="N";
return true;
}
This will write 'Y' and 'N' to the database instead of 1 and 0.
The only problem is that checkbox control won't recognize 'Y' and 'N' as a valid input.

Probably you can modify SQL query to convert Y and N back to 1 and 0 so checkboxes work fine.


Feature Request for the next release, How about adding the option to select what type of values to use when using a checkbox.....something similar to when using the upload option ( you need to provide a folder location).
Thank you!

J
Jane 9/27/2006

Hi,
here is a workaround how to display checkboxes in the Yes/No format on the LIST page:

Open include/commonfunctions.php file, find GetData function, locate following code snippet:

else if($format == FORMATCHECKBOX)

{

$ret="<img src=\"images/check";

if($data[$field] && $data[$field]!=0)

$ret.="yes";

else

$ret.="no";

$ret.=".gif\" border=0>";

}



and replace it with this one:

else if($format == FORMAT_CHECKBOX)

{

if($data[$field] && $data[$field]!=0)

$ret="yes";

else

$ret="no";

}