Forums

[SOLVED] How to make a "Send me a copy" checkbox option ?

Souliman 07 Sep, 2009
Hello everyone !
I have made a form with 2 email setup :
- 1 e-mail for me (with the IP of the person who filled the form);
- 1 e-mail for the person who filled the form (without his IP, and not with my personal e-mail adress).
Each e-mail has its proper template.

What I want to do :
to add a "Send me a copy" checkbox before the submit button,
so that if the box is checked : the 2 e-mail will be sent,
and if not : only the first e-mail (for me) will be sent.

Thank you for your help !!!

Souliman
GreyHead 07 Sep, 2009
Hi souliman,

This question was answered a few weeks ago. As far as I remember it involved using a little code snippet to enable and disable the emails depending on the checkbox value.

Bob
Souliman 07 Sep, 2009
Hi Bob,
I've searched for hours but I didn't find...
To precise my question : I have 2 Setup emails in my form, and I want to send the 2nd e-mail (which has a personnal template and doesn't include the IP adress of the person) only if a box is checked.
I think the solution is in the "On Submit code - before sending email", but : how to differentiate the 2 Setup emails (with their proper template) in the code ?

Thank you !

Souliman
Souliman 08 Sep, 2009
Hi Bob,
I'm searching the solution.
If someone has the solution, here is a simple form I made for the example :
<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 230px;">Name</label>
    <input class="cf_inputbox" maxlength="150" size="20" title="" id="text_2" name="text_1" type="text" />
  
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 230px;">E-mail address:</label>
    <input class="cf_inputbox" maxlength="150" size="20" title="" id="text_4" name="text_2" type="text" />
  
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 230px;">Subjet :</label>
    <input class="cf_inputbox" maxlength="150" size="20" title="" id="text_8" name="text_3" type="text" />
  
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textarea">
    <label class="cf_label" style="width: 230px;">Message :</label>
    <textarea class="cf_inputbox" rows="10" id="text_10" title="" cols="50" name="text_4"></textarea>
    
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_checkbox">
    <label class="cf_label" style="display: none;"></label>
    <div class="float_left">
      <input value="Receive a copy of the message by e-mail." title="" class="radio" id="check00" name="check0[]" type="checkbox" />
      <label for="check00" class="check_label">Receive a copy of the message by e-mail.</label>
      <br />
      

    </div>
    
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_button">
    <input value="Send" name="button_11" type="submit" style="cursor: pointer;" />
  </div>
  <div class="cfclear"> </div>
</div>


You can see that the name of the checkbox is : check0[] (with or without brackets?...).

I'm searching which code I have tu put in the "On Submit code - before sending email" to disable the second e-mail if the checkbox is not checked (I have setup 2 e-mails and each of them is enabled).

Thank you for your help !!!
GreyHead 09 Sep, 2009
Hi Souliman,

From the post I linked to:
$MyFormEmails->setEmailData(1, 'enabled', '0');//disable email 1
$MyFormEmails->setEmailData(2, 'enabled', '1');//enable email 2

Bob
Souliman 09 Sep, 2009

From the post I linked to:

$MyFormEmails->setEmailData(1, 'enabled', '0');//disable email 1
$MyFormEmails->setEmailData(2, 'enabled', '1');//enable email 2



Hello Bob,
thank you,
where and how do I put the reference to the state of the checkbox (checked or not) in the code ?

I'm reaaly not good in php...
GreyHead 09 Sep, 2009
Hi souliman,

Sorry, I have a backlog of other work today and don't have the time for a PHP primer.

Bob
Souliman 09 Sep, 2009
You're welcome !
I know you answer to a lot of questions in the forum.
I will wait.
No problem. 🙂
Souliman 10 Sep, 2009
Any one knows the solution ?
Souliman 21 Sep, 2009
Up again... 🙂
nml375 21 Sep, 2009
Hi souliman,
Sorry for the delays, and thanks for your patience.
In the "onSubmit - before email" code, add this:
<?php
$MyForm =& CFChronoForm::getInstance("$formname");
$MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);
$copyme = JRequest::getVar('check0', array(), 'POST', 'array', 0);

if (in_array('Receive a copy of the message by e-mail.', $copyme))
{
  $MyFormEmails->setEmailData(2, 'enabled', '1');
}
?>

The above code assumes the value of the checkbox being 'Receive a copy of the message by e-mail.', as shown in the previously posted formcode. It also assumes the "send me a copy" is the second email in the form (having id 2).

Let me know how it works out
/Fredrik
Souliman 21 Sep, 2009
Excellent !!!
Thank you Fredrik, infinitely !!!
It works perfectly.
The only thing I had to change was to disable the 2nd e-mail by default, so that when the checkbox is checked the "On Submit code" will force the 2nd e-mail to be sent.

Souliman
hengsovann 24 Oct, 2011
How this work on 4.0 RC2.0 + joomla 1.7?
I have test your code but it shown "Form name can NOT be empty!".
GreyHead 24 Oct, 2011
Hi hengsovann,

This is an old thread for ChronoForms v3. I think that are more recent threads describing how to do this in CFv4.

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