You are not logged in.
Pages: 1
I have an image slider that I'm building as a module. One of the fields that I added was a page ID, which would be used to identify the page you want the slider to appear on. One of the pages I'll be using it on is our homepage, but when I tried to save 0 in that field it would always get stripped out and saved as NULL. I think the problem is in the auto-modules class, specifically the sanitizeData function. In the part where integers are sanitized there is an that reads
if ($val !== 0 && !$val && $allow_null == "YES")
Since my 0 is considered a string (coming from the POST through a text input), it passes test one due to the type strictness, it passes test two because the 0 is loosely considered to be false, and then my $allow_null is set to yes so the third passes and my value is set to NULL.
I would imagine the way to fix this is either remove the second = off the first test so it'll accept strings/ints or change the second to check type as well with $val !== false.
Offline
I'll need to think on this one a bit, but I'll add it to the bug fix list! PHP's loose conversions are tricky. I think maybe this condition would be best:
if ($allow_null == "YES" && ($val === null || $val === false || $val === "")) {
That way we check for explicitly "empty" rather than falsey values. I guess there could be a case where someone really wants to store an empty string rather than NULL... but those edge cases might just have to be left to custom code. Thoughts?
Offline
I think you're right. The way you structured yours is better, be as specific as possible when checking for empty values so that everything else that should be valid can go through.
Offline
Cool, should be fixed in this commit:
https://github.com/bigtreecms/BigTree-C … 4aa6f0c0db
I gave it a test and it seems to work properly now but let me know if you still run into any related issues
Offline
Pages: 1