Welcome, Guest
Username: Password: Remember me

TOPIC: [FIXED] Boolean in backend item is always 1

[FIXED] Boolean in backend item is always 1 30 Dec 2011 14:31 #773

  • molenwal1
  • molenwal1's Avatar
  • Offline
  • Senior Member
  • Posts: 63
  • Thank you received: 17
  • Karma: 3
I have created a Publish field in several tables. I used the Publish wizard. I also set the default value to 1.

In the backend i have created an item form and put the Publish field into the form.

Now when i save an item with the Publish radiobox to No it will save a value 1 (Yes).

The reason is in the code in the table class check() function:
if (empty($this->publish))
			$this->publish = "1";

When you look at the return values of the php empty function a zero is considered as empty:
Returns FALSE if var has a non-empty and non-zero value.

The following things are considered to be empty:

"" (an empty string)
0 (0 as an integer)
0.0 (0 as a float)
"0" (0 as a string)
NULL
FALSE
array() (an empty array)
var $var; (a variable declared, but without a value in a class)


I think in case of a boolean the check with empty(value) is not correct because 0 is the No value!
Molenwal1 Webdesign
www.molenwal1.nl
Last Edit: 30 Dec 2011 14:33 by molenwal1.
The administrator has disabled public write access.

Re: Boolean in backend item is always 1 30 Dec 2011 14:57 #774

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Try with:

if ($this->publish === null)
Coding is now a piece of cake
The administrator has disabled public write access.

Re: Boolean in backend item is always 1 02 Jan 2012 06:01 #788

  • molenwal1
  • molenwal1's Avatar
  • Offline
  • Senior Member
  • Posts: 63
  • Thank you received: 17
  • Karma: 3
Ok, that works, maybe an idea to change this in the cook for boolean fields. When someone creates a boolean field in a form the same problem will occur.
Molenwal1 Webdesign
www.molenwal1.nl
The administrator has disabled public write access.

Re: Boolean in backend item is always 1 03 Jan 2012 21:19 #806

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Solved Since 1.4.6
Coding is now a piece of cake
The administrator has disabled public write access.
Time to create page: 0.072 seconds

Get Started