Forums

Trying to set hidden field before sending mails

jeango 02 Jun, 2011
Hi,
I have a form with a select input named "cours" and I want to send a mail according to what was selected in that input. So I set a hidden destmail field

Problem is: the magic doesn't happen, the destmail field is not updated...

here is my php code:

<?php
if (stripos($cours, 'cinéma') !== false)
{
   $destmail = 'cinema@acte4.be';
}
else if (stripos($cours, 'ados') !== false)
{
   $destmail = 'ados@acte4.be';
}
else if (stripos($cours, 'théâtre') !== false)
{
   $destmail = 'theatre@acte4.be';
}
?>


and here is the html of the select box:

<select size="1" id="cours" class=" validate['required']" title="" type="select" name="cours">
<option value="">(sélectionnez)</option>
<option value="théâtre">Théâtre</option>
<option value="cinéma">Cinéma</option>
<option value="ados">Ados</option>
<option value="stage cinéma juillet">Stage Cinéma Juillet</option>
<option value="stage cinéma août">Stage Cinéma Août</option>
<option value="stage ados juillet">Stage Ados Juillet</option>
<option value="stage ados août">Stage Ados Août</option>
</select>
GreyHead 02 Jun, 2011
Hi jeango,

You aren't actually getting a value for $cours anywhere. Please try
<?php
$cours = JRequest::getString('cours', '', 'post');
if (stripos($cours, 'cinéma') !== false)
{
   $destmail = 'cinema@acte4.be';
. . .

Nor are you doing anything with $destmail. Assuming that you have destmail in a Dynamic To box for your Email configuration you will need to add
. . .
{
   $destmail = 'theatre@acte4.be';
}
$form->data['destmail'] = $destmail;
?>

I think that will do the trick.

Bob
jeango 03 Jun, 2011
that did indeed do the trick, thank you
Small question though:
could I have just done $cours = $form->data['cours'] instead of calling the getString method of JRequest? was there a reason to get that information from the request header rather than the $form variable?
GreyHead 03 Jun, 2011
Hi jeango,

Either route will work, yours is probably better for CFv4. I'm just in the habit of using JRequest as that was the code used for CFv3.

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