Hello,
I have a form with a drop down list field in which the user chooses a Department.
Acording with the choosed Department, the Form should sent an email to a different email address (getting the email address from a table).
I'm trying this in the "On Submit code - before sending email" section of the Form Code tab.
But I don't know how to get the name of the Department choosed by the user.
I guess it's simple but...
Any idea? Any code?
Thanks in advance,
Gonzalo
Hi Gonzalo,
There's a FAQ about this #36 if I remember correctly.
Bob
Hi Bob,
Excelent! It's in FAQ 31.
That's what I need, also if I have to work on it a little more, as I want to get the emails from a table and not write them fisically in the code.
Again, Thanks.
Gonzalo
Hi Bob,
I have worked a lot on this, but I can't get the final result.
The FAQ you suggested has this code for the On submit section:
<?php
$emails_2 = array('em1'=>'sample1@email.com', 'em2'=>'sample2@email.com', 'em3'=>'name_3@example.com', . . .);
$MyForm =& CFChronoForm::getInstance('form_name_here');
$MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);
$MyFormEmails->setEmailData(1, 'to', $emails_2[$_POST['recipients']]);
?>
If I use it putting the emails manually in the code it works. But I would like to get the emails from a table (in order that they can be changed by the Secretary).
I'm trying putting the emails from the table in a string variable with, a While, and using that variable in the Array. But I get no email address to send.
This is the string I get in the variable $arraq: 'Masters'=>'masters@uprait.org', 'Informazioni Generali'=>'info@uprait.org', 'Diploma'=>'diploma@uprait.org', 'Filosofia'=>'filosofia@uprait.org'
Then I have this:
$emails_2 = array($arraq);
And then the rest of the code:
$MyForm =& CFChronoForm::getInstance('A_test');
$MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);
$MyFormEmails->setEmailData(1, 'to', $emails_2[$_POST['recipients']]);
I don't know how to put the string into the Array in a correct way.
Any idea?
Thank you,
Gonzalo
Hi Bob,
Once again, thaks for your answer.
It's exactly the logic of what I need.
I have tryied the code but I get this error for the 3th line:
Fatal error: Call to undefined method JRequest::gstString() in /web/htdocs/www.uprait.org/home/components/com_chronocontact/libraries/customcode.php(64) : eval()'d code on line 3
I get it also if I put just this code:
<?php
$db =& JFactory::getDBO();
$dept_name =& JRequest::gstString('recipients', '', 'post');
echo $dept_name;
?>
Is there something wrong?
Hi Bob,
I've noticed a type error: gstString()
I have changed it into getString() and the error disappeared.
I must try yet the rest of the code.
Thanks,
Gonzalo
Hi Bob,
Just great!
Thank you very very much.
Gonzalo
Hi Gmiranda,
Great, sorry about the typo :-(
Bob
Hy Bob,
I must be honest: the typo was mine! You put the correct code, but copying it I made the error. đ¶
Thanks again,
Gonzalo
Hi,
I think I did as you say, but no email is sent...
I enclose a creenshot to give an idea of what I did.
Thanks for your help.[attachment=0]screen.gif[/attachment]
Thank you for that.
I put the right details (see below). However, no email is sent.
Do I have to fill in the "setup emails" header ?
thanks.
[attachment=0]screen.gif[/attachment]
Hello jfgarcia,
If course you put the option "Email the results ?" into Yes !?
You could try using the Debug (Debug: ON) to see what happens.
Gonzalo
Hi Bob,
Going back to my code for sending different emails, I would need to send to several email addresses when the user chooses a Department.
In the email table I have them separated with commas, but the code sends de mail only to the first one.
Is it possible to do the trick whit that code?
Thanks!
Gonzalo
Hi Gonzalo,
I think it should work OK if you have a comma separated list (if not then try with an array).
If you post the code you are using it's easier to comment.
Bob
Hi Gonzales,
And what is in the database column?
Bob
Do I have to put something in the Form tag attachment field?
[attachment=0]screen.gif[/attachment]
thanks.
Hi jfgarcia,
You shouldn't need anything there. Is the email enabled in the Email Setup Properties box?
If it is then you will see enabled:1/disabled:0 in the Email column of the Form Manager list.
Bob
ok, but I can't turn the email to "enabled". As you can see, it can't be changed:
[attachment=0]screen.gif[/attachment]
Hi jfgarcia,
Both your email templates are lacking the mandatory 'From Email', 'From Name', and 'Subject' properties (or their dynamic counterpart). You will not be able to enable a email template without all these properties, and the underlying mailer will generally not be able to send the email without proper values assigned to them.
/Fredrik
Hi,
That's the trick!
You must put all those parameters in the email templates. When you put them, the box changes it's colour. Then you can enable the email.
I had the same problem some time ago, but I did not remember that.
I found the trick reading one of the pdf that you can download ("Adding emails to a form in ChronoForms"). Sometimes it's not a bad idea to read de manuals...
Gonzalo
Thank you guys, I will try that and let you know...
Cheers.
JF
Greeeaaat!
That was the thing, it works now.
thanks again.
Cheers.
JF