problems with checkbox in mail

ma mart1jn 05 Aug, 2009
I upgraded to ChronoForms V3.1 RC5.5 and it seems this introduced a new problem.

My form has several check boxes. E.g.:

<input type="checkbox" name="hulp_opruimen_donderdag" value="ja" tabindex="53">

In the mail sent by chronoform this used to be printed as follows:
if checkbox was selected: Opruimen donderdag ja
if checkbox wasn't selected: Opruimen donderdag <empty>
(where <empty> means nothing is printed)

now with rc 5.5 the behaviour is as follows:
if checkbox was selected: Opruimen donderdag ja
if checkbox wasn't selected: Opruimen donderdag {hulp_opruimen_donderdag}

i.e. it prints the fieldname between braces (is this a bug or is it because i made a mistake?).

my preferred behaviour would be:
if checkbox was selected: Opruimen donderdag ja
if checkbox wasn't selected: Opruimen donderdag nee

is there a solution to this bug or (better) is there a way to create my preferred behaviour?
Thanks in advance.
Gr GreyHead 05 Aug, 2009
Hi mart1jn,

I don't know where the <empty> came from.

A checkbox has an entry in the $_POST array if it is checked but not if it isn't. So you'll get back either 'ja' or nothing. You can add a couple of lines of code in the Onsubmit Before box to switch that to 'nee'.
<?php
JRequest::setVar('hulp_opruimen_donderdag', JRequest::getString('hulp_opruimen_donderdag', 'nee', 'post'));
?>
Not tested and may need de-bugging!

This reads the $_POST array using 'nee' as a default value and re-writes the result back to the $_POST array.

Bob
ma mart1jn 05 Aug, 2009
hi Greyhead,

Thanks, your piece of code works, I do get the "nee" printed with that (after adding an extra ' behind 'post).

You helped my solve that problem. Only the question remains why with rc 5.5 the default behaviour changed, i.e. why is {fieldname} returned by default instead of an empty value when the checkbox isn't checked. It would be nice if that default behaviour would still work.
Gr GreyHead 05 Aug, 2009
Hi mart1jn,

I didn't even know there was 5.5 release until I read your post, so I've no idea what has changed. As I said I don't know where the <empty> came from in the older version either.

Bob

PS Fixed the missing ', sorry.
Max_admin Max_admin 06 Aug, 2009
Hi mart1jn,

I agree, please contact me through the contact us page to get a fixed file!

Regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
ma mart1jn 06 Aug, 2009
Hi Greyhead,

Sorry I probably haven't been very clear about what I meant with <empty>. In previous versions, when leaving the checkbox unchecked, the mail message would leave the value empty. I tried to designate that with <empty> but i might also have brought it this way:

In the mail sent by chronoform this used to be printed as follows:
if checkbox was selected: Opruimen donderdag ja
if checkbox wasn't selected: Opruimen donderdag

I hope that clarifies.

Anyway your solution is what I was looking for, and admin sent me a fix for the issue, so now again an empty value is printed instead of {fieldname} when the checkbox wasn't checked.

So thanks very much to you and admin for the great help!
all the best,
mart1jn.
Gr GreyHead 07 Aug, 2009
Hi mart1jn,

That's clear - sorry, I'd misunderstood.

Bob
sa saber 17 Dec, 2010
I have got the same problem here. Please - how can I fix it?
Gr GreyHead 17 Dec, 2010
Hi saber,

Please say exactly what problem you have.

Bob
sa saber 17 Dec, 2010
When the checkbox wasn't checked in the email appeares {fieldname} instead of just "nothing".

<input type="checkbox" name="Musik" id="Musik" value="Ja" />
Gr GreyHead 18 Dec, 2010
Hi saber,

An unchecked checkbox doesn't return any value from the form so there is nothing for hronoForms to replace the {filedname} with.

Use this code in the OnSubmit Before box:
<?php
$Musik = JRequest::getString('Musik', 'Nein', 'post');
JRequest::setVar('Musik', $Musik);
?>

Bob

Later: removed a stray comma
sa saber 18 Dec, 2010
Thank you GreyHead
but unfortunately this doesn't have any effect.
Gr GreyHead 18 Dec, 2010
Hi saber,

There was an extra , in this line:
$Musik = JRequest::getString('Musik', 'Nein', ,'post');
it should be
$Musik = JRequest::getString('Musik', 'Nein', 'post');


Bob
sa saber 18 Dec, 2010
Thank you - you just made my day!
It works perfectly now:

Literatur Nein
Musik Ja
Malerei Ja
Psychologie Nein
Psychiatrie Nein
...
This topic is locked and no more replies can be posted.