Folks, as some of you may know, the post() function was recently updated. The new version is more robust and versatile. Improving the post() function was essential for reasons that I'll discuss in a minute.
But first, there's a problem that I need to tell you about.
THE PROBLEM
Unfortunately, the new post() function has highlighted an issue with how checkbox values are handled.
If you are using the (brand new) post() function to fetch posted values from checkboxes then there's a chance that your checkboxes will always be received as 0 (zero - an integer).
WHY IS THIS HAPPENING?
The reason why this is happening is because the code generator (at the time of writing) produces the following code for receiving values that have been posted via checkboxes:
This worked well with the old post() function but with the new post() function, $data['active'] will always be assigned with a value of 0 (int).
THE FIX
The new recommended pattern for receiving posted checkbox values is:
This ensures a clean 1 or 0 result every time, and it works exactly as expected, without relying on loose comparisons or unpredictable casting.
SHOULDN'T WE JUST GO BACK TO USING THE OLD POST FUNCTION?
Some of you may be thinking, “Why not just stick with the old post() function?”
That’s a fair question, and one worth unpacking properly.
The short answer is: the old post() function was doing *too much* behind the scenes. It didn’t just retrieve data - it *mutated* it. Most notably, it would automatically convert numeric-looking strings into integers or floats. That might seem convenient, but in reality, it introduced subtle bugs that were often hard to detect.
Here’s a concrete example:
Imagine a user fills in a form with their UK mobile number:
Now, let’s say your code includes:
With the **old** post() function, that mobile number - `"07700123456"` - gets auto-cast to an integer:
Suddenly, the mobile number is no longer valid. The leading zero is gone. If you're storing that in a database, sending it in a text message, or comparing it against another value, you’ve now got a broken piece of data.
That bug didn't come from your form. It didn’t come from your controller. It came from the helper, silently making decisions on your behalf.
With the **new** post() function, that same line of code:
...returns exactly what the browser sent:
No surprise casting. No broken data. You get full control over how and when to cast or clean the data, which is how it should be.
So the reason we moved away from the old post() is simple: the new version is safer, more predictable, and puts developers back in charge of their data. It might mean writing an extra cast here and there, but it prevents the kinds of hidden bugs that can waste hours - or worse, go unnoticed in production.
A MASSIVE PAIN IN THE ARSE
To be clear, this kind of thing is a pain in the arse when it happens. That's because it creates a slightly miserable situation where we have to choose between convenience vs doing it right.
The responsible decision, I think, is to just do it right.
So, unfortunately, this is one of those very rare situations where you may have to make some manual changes to your code.
I apologise for any inconvenience that this may cause. It's all my fault.
IN SUMMARY
Where you are accepted posted checkboxes, change your code from (something like):
...to...
Just to let you know: I ran all of this past four different AI bots and they all agree that this is the best way forward.
Remember folks, stability is the number one priority for Trongate.
DC
A special welcome to our newest member, KnoldTot.
Handling Checkboxes SUPER IMPORTANT
#1
23 Jul 2025, 9:15am UTC
Wednesday 23rd July 2025, at 9:15am UTC
Edited on Wednesday 23rd July 2025, at 9:23am UTC
#2
23 Jul 2025, 9:28am UTC
Wednesday 23rd July 2025, at 9:28am UTC
I've updated the code generator so that checkboxes are now handled in the newly recommended manner.
#3
23 Jul 2025, 9:31am UTC
Wednesday 23rd July 2025, at 9:31am UTC
David, How did you handle checkboxes in the generator?
Thanks, Dan
Thanks, Dan
This post was liked by; Davcon
#4
23 Jul 2025, 10:54am UTC
Wednesday 23rd July 2025, at 10:54am UTC
Hi Dan,
The code generator sends HTTP requests to this website and this website returns the PHP code. It means that we can change how the code generator works without having everyone download a new version each time there's a change.
Here's the (controller) code that handles the bit you mentioned:
And here's the corresponding view file ('pre_insert_line_bool.php'):
The code generator sends HTTP requests to this website and this website returns the PHP code. It means that we can change how the code generator works without having everyone download a new version each time there's a change.
Here's the (controller) code that handles the bit you mentioned:
And here's the corresponding view file ('pre_insert_line_bool.php'):
Edited on Wednesday 23rd July 2025, at 10:55am UTC
This post was liked by; DaFa
#5
23 Jul 2025, 12:16pm UTC
Wednesday 23rd July 2025, at 12:16pm UTC
very nice.