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!
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
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
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!!
<?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);
?>
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!!!
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!!!!!
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
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?
Thanks!!!
Regards
Max
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!
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.
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>
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 ?
Je veux envoyer un e-mail différent en fonction de ce qui a été coché dans la checkbox
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
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 😢
Please try changing to
$check2 = JRequest::getVar( 'check2', '', 'post', 'array');Bob
It works perfectly. I hope my english is not too bad 😶
I can now work with chronoconnectivity
Merci beaucoup!🙂
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
$check2=array ('answer1','answer2');I receive well the mail 1 and 2.
The problem is always to recover the values of this checkboxes :twisted:
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 lineBob
One more attempt:
$check2 = JRequest::getVar( 'check2', '', 'post');
$check2 = explode(', ', $check2);Bob
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 :?
My last post for a few days.
I had an extra space in the explode
$check2 = JRequest::getVar( 'check2', '', 'post');
$check2 = explode(',', $check2);Bob
