Dec 5th, 2011, 2:36 AM
(Dec 4th, 2011, 2:08 PM)Ben Wrote: Ahh! Yeah, this just tripped me up myself.
So the funny thing about checkboxes is that if nothing's checked, nothing will be sent along in the POST request and that particular field won't be updated in the database. Sadly, this is just the way HTTP works for form submissions.
So to get around it with API forms, you need to add in a line of code to say if the form has been submitted and there's nothing for the checkbox field, set it to blank. Otherwise, store whatever value is being passed.
Here's some example code:
PHP Code:<?php
$fields = ft_api_init_form_page();
// ...
if (isset($_POST["your_submit_btn_name"])) {
$_POST["cb_name"] = (isset($_POST["cb_name"])) ? isset($_POST["cb_name"]) : "";
}
// ...
$params = array(
// ...
);
?>
You'll need to change "your_submit_btn_name" to, well, your submit button name, and "cb_name" to whatever name attribute your checkbox fields have.
I put the other code in just to give you an idea of where it should go.
Hope this helps!
- Ben
Awesome! Fabulous! Gorgeous! Brilliant!
That works beautifully and it has now solved my problem.
Thanks Ben, Genius!