Sending mail depending checkboxes

StefanJ 04 Feb, 2011
I use chronoforms on all my websites.
It is useful that the code can be modified

Now I am looking for a piece of code which will not, when a certain checkbox is checked, email the data.

For example:
Have you ever had contact? Option: Yes | No
Under both options, the form should be sent, but with option no, I do not want in my mailbox.
Below the current code:
<div class="form_item">
<div class="form_element cf_checkbox">
<label class="cf_label" style="width: 180px;">Ever had contact before?</label>
<div class="float_left">
<input value="yes" title="Required field !" class="radio validate-one-required" id="check00" name="check0[]" type="checkbox" />
<label for="check00" class="check_label">Yes</label>
<input value="No" title="Field required !" class="radio validate-one-required" id="check01" name="check0[]" type="checkbox" />
<label for="check01" class="check_label">No</label>
<br />
</div>


Does anyone here have a solution?

grtz

Stefan
GreyHead 04 Feb, 2011
Hi Stefanj,

In the Email Setup | Properties box set Enabled to 'No'. Then add this code to the OnSubmit Before Email box.
);
$check0 = JRequest::getVar( 'check0', '', 'post');
if ( $check0 == 'yes' ) {
  $MyFormEmails->setEmailData(0, 'enabled', '1');
}
?>

and edit your Form HTML so you have a pair of radio buttons instead of two checkboxes (which could both be checked).
<input value="yes" title="Required field !" class="radio validate-one-required" id="check00" name="check0" type="radio" />
<label for="check00" class="check_label">Yes</label>
<input value="no" title="Field required !" class="radio validate-one-required" id="check01" name="check0" type="radio" />
<label for="check01" class="check_label">No</label>




Bob
StefanJ 05 Feb, 2011
Sorry GreyHead,

I tried your solution but it will not work.
The data is stored in the database, for both options (yes and no).
But the form does not send any emails anymore.

What can I do wrong?
GreyHead 05 Feb, 2011
Hi StefanJ,

Please take a Form Backup using the icon in the Forms Manager and post it here (as a zipped file) or PM or email it to me and I'll take a closer look.

Bob
StefanJ 05 Feb, 2011
Thanks for your quick reply!
I added the back-up file.

gr

Stefan
GreyHead 05 Feb, 2011
Hi Stefanj,

Two little mistakes in my code :-( Here's the corrected version:
<?php
$check0 = JRequest::getVar( 'check0', '', 'post');
if ( $check0 == 'yes' ) {
  $MyFormEmails->setEmailData(1, 'enabled', '1');
}
?>

Bob

a) the first line should be <?php
b) the Email id is 1, not 0 after setEmailData(
StefanJ 05 Feb, 2011
Hi Bob,

You're the man!!
Very good.
It works!
Thanks a lot.

grtz

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