Get checkbox value in email

Loko 09 Apr, 2013
Hello

In a custom code CF I have several "single group" checkbox but I get their {name} in the email instead of their values.

I dit include an HandleArray event on submit and included [] in their names. I can't figre out where I'm wrong.

Can anyone tell me ?

I wanted to attach an export of my form but it says the cf4bak extension is not allowed, thus I zipped it.

Thank you
Loko
GreyHead 09 Apr, 2013
Hi Loko,

For single checkboxes you don't need the [] or the Handle Arrays action (you do for the Multiple drop-down though).

I suspect that your problem is that un-checked check boxes return nothing in the form data. There is no entry at all so you need to add one. You can do this - as the ChronoForms Wizard does - by adding ghost entries, hidden inputs in the form HTML before the checkboxes with the value='0' in your case.

Or you can check the results using PHP in a Custom Code action in the On Submit event to see what is missing and add values then.

Bob
Loko 10 Apr, 2013
Hi Bob

Yes, I tried without the [] first, but as it didn't work I gave them a try.

OK so I added 1 hidden field for each checkbox name "hidden_checkboxname" then added a LoadJS action on submit to give thoses fields values, but it seems that my code is never ran, I included an "alert" for debug at the beginning of my code and it did not raise.
I did not included the script tags in the LoadJS action.

Now in the email I can't see the checkboxes names anymore so I guess it correctly handles the hidden fields, but I miss my javascript to be executed to get values.

Loko

document.getElementById("podium_sportif_qte").checked ? document.getElementById("hidden_podium_sportif_qte").value = '1' : document.getElementById("hidden_podium_sportif_qte").value = ' ';
document.getElementById("grand_podium_6_par_6_qte").checked ? document.getElementById("hidden_grand_podium_6_par_6_qte").value = '1' : document.getElementById("hidden_grand_podium_6_par_6_qte").value = ' ';
document.getElementById("sono_portative_lot'1'").checked ? document.getElementById("hidden_sono_portative_lot'1'").value = '1' : document.getElementById("hidden_sono_portative_lot'1'").value = ' ';
document.getElementById("sono_portative_lot2").checked ? document.getElementById("hidden_sono_portative_lot2").value = '1' : document.getElementById("hidden_sono_portative_lot2").value = ' ';
document.getElementById("ecran_projection_24_par_'1'8_qte").checked ? document.getElementById("hidden_ecran_projection_24_par_'1'8_qte").value = '1' : document.getElementById("hidden_ecran_projection_24_par_'1'8_qte").value = ' ';
document.getElementById("ecran_projection_'1'3_par_'1'25_qte").checked ? document.getElementById("hidden_ecran_projection_'1'3_par_'1'25_qte").value = '1' : document.getElementById("hidden_ecran_projection_'1'3_par_'1'25_qte").value = ' ';
GreyHead 10 Apr, 2013
Hi Loko,

I'm not sure why you need the JavaScript? What is that doing? Just a fixed hidden input should be enough.

Bob
Loko 10 Apr, 2013
I don't know exactly what the wizard does with ghost entries, I'm just trying to to get values into hidden fields according to the checked property of the checkboxes.

Could you please give me more details on how to do this with custom form code ?

For instance I have :


<td><div align="center">
<input id="hidden_podium_sportif_qte" type="hidden" name="hidden_podium_sportif_qte" />                    
<input name="podium_sportif_qte" id="podium_sportif_qte" type="checkbox" />
</div></td>


What are the rules for my hidden input to get its value, as you said, from the checkbox ? (My javascript aims at that but is not ran.)
If you say it's automatic I guess I miss or have misunderstood something ...

Loko
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount
hostinger