Forums

Send e-mail dependent on checkboxes

bristolcat 23 Jun, 2009
Greetings! First, thank you for this fantastic component. I have been able to do exactly what I want with it so far, which is helping me out a lot. I do have a question, however, on one thing. I'm doing an RSVP form and trying to create custom e-mail responses, based on whether or not they can come to the event or not. I've spent a lot of time going through the forums in hopes of figuring this out myself, but I'm running short on time and figured I'd swallow my pride and ask for help!

My setup is as follows:

-A variety of required fields, such as name, e-mail, etc.
-Three RSVP checkboxes:
-Can attend event 1
-Can attend event 2
-Unable to attend events
-A variety of additional fields that the user can fill out if they are attending - these show up dynamically when the user clicks on one of the first two checkboxes, which I created following the instructions in number 47 of the FAQ.

What I'd like to do is send a confirmation e-mail to anyone who clicks on one or both of the first two checkboxes, thanking them for registering for the event and supplying additional information. If they click on the last checkbox, then they will get a message stating that we're sorry they cannot attend.

I've studied this forum post, in hopes of getting it to work for checkboxes, but I've had no luck: http://www.chronoengine.com/forums/index.php?option=com_chronoforums&cont=posts&f=5&t=14295&p=32067&hilit=different+emails#p32067 I would prefer not to use a dropdown, since I have two different events that they can or cannot attend.

I currently have three e-mails set up. The first e-mails me, the admin. The second e-mails the user, using a dynamic to, with a confirmation. The third e-mails the user, using a dynamic to, with a "thank you and sorry you won't be there" e-mail.

I'm not very good with PHP, so anything you can spell out thoroughly would be much appreciated. Thanks so much!
Max_admin 23 Jun, 2009
Hi bristolcat,

Its too late here, but I will give you some guidelines which may help, if you can't do it then let me know!

set the 3 emails as disabled then use this code in the onSubmit after email box


<?php
$formname = 'myformname';
$MyForm =& CFChronoForm::getInstance($formname);
$MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);
if(JRequest::getVar('check_will_attend_on')){
$MyFormEmails->setEmailData(1, 'enabled', 1);
}
$MyFormEmails->sendEmails($MyForm, $MyFormEmails->emails);
?>


I dynamically enable the first email if the will attend checkbox is checked, you will need to supply the form name and your check box name!

Cheers
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
bristolcat 23 Jun, 2009
Hi Max! Thanks for your reply, and sorry for keeping you up late.

I feel like I'm close, but I'm not entirely sure what I'm supposed to be replacing in the code.

Here are my checkboxes:

<div class="form_item">
  <div class="form_element cf_checkbox">
    <label class="cf_label" style="width: 150px;">Select the events you plan on attending. If you cannot join us, select "Unable to attend." </label>
    <div class="float_left">
      <input value="Friday dinner" title="friday" class="radio validate-one-required" id="check00" name="check0[]" type="checkbox" value="No" rel="morersvp" />
      <label for="check00" class="check_label">Friday dinner</label>
      <br />
      
<input value="Saturday picnic" title="saturday" class="radio validate-one-required" id="check01" name="check0[]" type="checkbox" value="No" rel="morersvp"/>
      <label for="check01" class="check_label">Saturday picnic</label>
      <br />
      
<input value="Unable to attend" title="unable" class="radio validate-one-required" id="check02" name="check0[]" value="No" type="checkbox" />
      <label for="check02" class="check_label">Unable to attend</label>
      <br />
      

    </div>


I'm sorry for being so clueless. I appreciate your help - I feel like I should know how to do this, but everything I try doesn't quite work! Thanks!!
Max_admin 24 Jun, 2009
Hi, can they choose the first 2 events or only selection is allowed ?

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
bristolcat 24 Jun, 2009
I'm not entirely sure what you are asking, but I'll try to be more clear. They can pick either one of the first two checkboxes (two separate events) or both, or they can select the third checkbox to say they aren't coming at all. The event confirmation email would go to the recipient if one or more of the first two boxes were checked. A generic thank you email goes to anyone who selects the third option.

If you know of a better way to do this, I'm open to suggestions. I know that they technically can select both an event and the unable to attend box and get both e-mails, but I'm hoping common sense will prevail over that.

Thanks!!
Max_admin 25 Jun, 2009
based on your answers, I think that my code should be this:


    <?php
    $formname = 'myformname';
    $MyForm =& CFChronoForm::getInstance($formname);
    $MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);
    if(in_array('Friday dinner', JRequest::getVar('check0'))){
    $MyFormEmails->setEmailData(1, 'enabled', 1);//enable first email if they will join the first event
    }
if(in_array('Saturday picnic', JRequest::getVar('check0'))){
    $MyFormEmails->setEmailData(2, 'enabled', 1);//enable 2nd email if they will join the 2nd event
    }
    $MyFormEmails->sendEmails($MyForm, $MyFormEmails->emails);
    ?>

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
bristolcat 25 Jun, 2009
Thanks again for your reply and for supplying me with the code! I appreciate your work and your component.

I am getting an error when I try submitting the form. When I hit submit, I get the following:

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/sitedir/public_html/website.com/components/com_chronocontact/libraries/customcode.php(42) : eval()'d code on line 5

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/sitedir/public_html/website.com/components/com_chronocontact/libraries/customcode.php(42) : eval()'d code on line 8



I'm going to keep trying some different things here, but I thought I'd post that in case you have any ideas.

Thanks!!!
bristolcat 25 Jun, 2009
I have been working on this problem for hours, and I still can't get it to work. I'm going to feel really stupid if it's something simple, but I just can't get it! So, I figured I'd re-post with some more info.

My form's name is "RSVP"
I renamed my checkbox values to "fridaydinner" and "saturdaypicnic"

The code that you provided me with, I pasted into the On submit after box like this:

<?php
    $formname = 'RSVP';
    $MyForm =& CFChronoForm::getInstance($formname);
    $MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);
    if(in_array('fridaydinner', JRequest::getVar('check0'))){
    $MyFormEmails->setEmailData(1, 'enabled', 1);//enable first email if they will join the first event
    }
if(in_array('saturdaypicnic', JRequest::getVar('check0'))){
    $MyFormEmails->setEmailData(2, 'enabled', 1);//enable 2nd email if they will join the 2nd event
    }
    $MyFormEmails->sendEmails($MyForm, $MyFormEmails->emails);
    ?>


Note that the only things I edited in this code were changed "myformname" to "RSVP" on line two, and then edited the value names to match the new ones ("fridaydinner" instead of "Friday dinner").

I Googled and discovered that this kind of error is returned if it doesn't find the array or the array has nothing in it. I checked, however, and the database has been storing the data just fine. I Googled again and found a script that would test whether $check0 was an array or not, and it came back saying that it was not.

I did dig around on the forum here and found several people who had database issues with multiple checkboxes. I tried fixes and other things I saw in those posts, but nothing worked. I do have "ChronoForms handle my posted arrays" set to YES and I do not have a redirect set.

If it helps, I'll post my Debug here (left most of the fields blank - checkbox in question is check0):

1. Form passed first SPAM check OK
2. Form passed the submissions limit (if enabled) OK
3. Form passed the Image verification (if enabled) OK
4. Form passed the server side validation (if enabled) OK
5. $_POST Array: Array ( [text_2] => Name [text_3] => LastName [text_4] => [email]test@test.com[/email] [check0] => Array ( [0] => fridaydinner ) [text_6] => [text_14] => [text_15] => [text_16] => [text_18] => [Submit] => Submit Query [fdaddecc0b8fe4a339d7e837789ed1c4] => 1 [1cf1] => 1c613a53ea10f8e6cd6049eb2c848ae7 [chronoformname] => RSVP )
6. $_FILES Array: Array ( )
7. Form passed the plugins step (if enabled) OK
8. Debug End



So hopefully someone will be able to help me solve this mystery. I'm running out of time and I'd rather not have to try to get a different form component to work this late in the game. Thanks!!!!!
Max_admin 26 Jun, 2009
Hi,

first thing I see is that you changed the code so it now says "fridaydinner" instead of "friday dinner", did you make the same change in your HTML ? or the code will not work as intended!

I hope you didn't change anything else as well but try to replace
JRequest::getVar('check0')
by
$_POST['check0']
and see if it works!

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
bristolcat 26 Jun, 2009
Max, thanks for trying again, but it still didn't work. I'm at a loss here - everything in the HTML matches the php code exactly. Just to make sure, I even went back and used the original code with the original names, but it still didn't work. I get the exact same error.

I am still trying to figure out if it's getting connected to the database properly, or if it's an issue with the checkbox array. I may try some other stuff to see if I can get closer to figuring out this mystery, but I have limited skills and although I'm learning a ton digging around in this, I can only go so far.🙂 I really appreciate your time and help. On the upside, while researching this problem, I solved a different one related to a different form!

Would it be worth it to try rebuilding the form from scratch and trying it again?
bristolcat 27 Jun, 2009
I am simultaneously throwing in the towel and declaring victory on this one. I worked on this all night and all morning, but finally decided to rebuild the form and use a dropdown box to decide which e-mail to send, rather than a checkbox. It worked like a dream. The checkbox array situation is just plain over my head, but using the instructions on the aforementioned forum post that I found initially, I was able to get the dropdowns working. It's not ideal, but I have to launch this site today.

Thanks!!!
Max_admin 28 Jun, 2009
Hi, I'm glad you found a workaround, not sure why my code wouldn't work, sometimes it needs debugging and testing but its hard to do this now because I'm here alone and Bob is off

Regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
laurent0 10 Nov, 2009
Hi

I update this post because I want to do the same.
I try since yesterday but I don't find the solution.
If any body have idea to help me🙂

Sorry for my english but i speek french 😶

Thanks so much!
GreyHead 10 Nov, 2009
Salut Laurent,

Tell us in more detail what you need to do. It's easier to explain with a real example.

Bob

Dites-nous plus en détail ce que vous devez faire. C'est plus facile d'expliquer un exemple réel.
laurent0 10 Nov, 2009
Hello, thanks for your answer in french moreover 😛

I have a checkbox with 4 possible answers. If I check the first, it send the first mail.

Example :

Checkbox answer1 --> send mail 1
Checkbox answer2 --> send mail 2
Checkbox answer1 --> send mail 3
Checkbox answer4 --> send mail 4

I think the problem is to recover the checkbox value.

Here is the code of my form (formname = Inscription)

  <div class="form_element cf_checkbox">
    <label class="cf_label" style="width: 150px;">Checboxes</label>
    <div class="float_left">
      <input value="answer1" title="" class="radio" id="check20" name="check2[]" type="checkbox" />
      <label for="check20" class="check_label">answer1</label>
      <br />
      
<input value="answer2" title="" class="radio" id="check21" name="check2[]" type="checkbox" />
      <label for="check21" class="check_label">answer2</label>
      <br />
      
<input value="answer3" title="" class="radio" id="check22" name="check2[]" type="checkbox" />
      <label for="check22" class="check_label" answer3</label>
      <br />
      
<input value="answer4" title="" class="radio" id="check23" name="check2[]" type="checkbox" />
      <label for="check23" class="check_label">answer4</label>
      <br />
      

    </div>
    
  </div>

GreyHead 10 Nov, 2009
Hi laurent,

One more question. Do you want to send the same email but to a different address; or to send a different email?

Bob
[en Bretagne]

Encore une question. Vous voulez envoyer le même email, mais à une adresse différente, ou envoyer un e-mail différente ?
laurent0 10 Nov, 2009
I want to send a different email according to the choice

Je veux envoyer un e-mail différent en fonction de ce qui a été coché dans la checkbox
GreyHead 11 Nov, 2009
Hi Laurent,

Try this - may need tweaking
<?php
$formname = JRequest::getVar('chronoformname');

if ( !$formname ) {
   $params   =& $mainframe->getPageParameters('com_chronocontact');
   $formname = $params->get('formname');
}

$MyForm =& CFChronoForm::getInstance("$formname");
$MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);

$answer_array = array (
  'answer1' => 1,
  'answer2' => 2,
  'answer3' => 3,
  'answer4' => 4,
  'answer5' => 5
);
$check2 = JRequest::getVar( 'check2', '', 'post');
foreach ( $check2 as $v ) {
  $v = $answer_array[$v];
  $MyFormEmails->setEmailData($v, 'enabled', '1');
}
?>
You need to 'disable' all emails in the Email Setup Properties for this to work. It will then enable the emails that match the checked boxes.

Bob
laurent0 11 Nov, 2009
Hi,

Thanks for your works.

I have tried your code but there is an error :
Warning: Invalid argument supplied for foreach() in /homez.68/espacedu/www/components/com_chronocontact/libraries/customcode.php(64) : eval()'d code on line 19

If I write on line 18 : $check2 = array ('answer1','answer2'), it works.
So I suppose the problem is to recover the value of check2

I have replace $check2 = JRequest::getVar( 'check2', '', 'post'); by $check2 = $_POST['check2'] but I have the same problem 😢
GreyHead 11 Nov, 2009
Hi laurent0.

Please try changing to
$check2 = JRequest::getVar( 'check2', '', 'post', 'array');


Bob
laurent0 11 Nov, 2009
Thanks a lot,
It works perfectly. I hope my english is not too bad 😶

I can now work with chronoconnectivity

Merci beaucoup!🙂
laurent0 12 Nov, 2009
Hi,

There is still a problem in the code 😶

If I check 2 boxes, no email is sent.

Example :

I check answer1 --> mail 1

If I check answer1 + answer2 --> no mail
laurent0 12 Nov, 2009
If I write :
$check2=array ('answer1','answer2');


I receive well the mail 1 and 2.

The problem is always to recover the values of this checkboxes :twisted:
GreyHead 12 Nov, 2009
Hi Laurent0,

Please add an extra line to show the value in check2
$check2 = JRequest::getVar( 'check2', '', 'post', 'array');
echo '<div>$check2: '.print_r($check2, true).'</div>'; // add this line

Bob
laurent0 12 Nov, 2009
Hi,

If I check answer 1 and 2 :

$check2: Array ( [0] => answer1, answer2 ) 
GreyHead 12 Nov, 2009
Hi Laurent0,

Ah OK - not what I was expecting. I'll take a look shortly.

Bob
GreyHead 12 Nov, 2009
Hi Laurent0,

One more attempt:
$check2 = JRequest::getVar( 'check2', '', 'post');
$check2 = explode(', ', $check2);

Bob
laurent0 12 Nov, 2009
Hi,

Thanks very much for your help.
But It works not enough 😢

with your last code, when I check answer 1 and 2, I have in variable check2 :

$check2: Array ( [0] => ) 


and no email :?
GreyHead 12 Nov, 2009
Hi Laurent,

My last post for a few days.

I had an extra space in the explode
$check2 = JRequest::getVar( 'check2', '', 'post');
$check2 = explode(',', $check2);

Bob
laurent0 13 Nov, 2009
:mrgreen:

I have just had a space in the code and it works because the value of $check2 before the explode
=answer1, answer2

$check2 = JRequest::getVar( 'check2', '', 'post');
$check2 = explode(', ', $check2);


Thanks a lot for your nice work, i'm very happy 😀
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount

{item:title} {images:#}