Forums

Choosing e-mail address from a list

rcadmin 17 Nov, 2010
Hi, I am using the ChronoForms 1.3 for Joomla! Site Cookbook ... which is a GREAT book.

Alas I am still doing something wrong.

My form looks like this
<div class="form_item">
  <div class="form_element cf_dropdown">
    <label class="cf_label" style="width: 150px;">Title</label>
    <select class="cf_inputbox validate-selection" id="select_1" size="1" title=""  name="Title">
    <option value="">Choose Option</option>
      <option value="Mr">Mr</option>
<option value="Mrs">Mrs</option>
<option value="Ms">Ms</option>
<option value="Dr">Dr</option>
<option value="Prof">Prof</option>
<option value="Other">Other</option>

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

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 150px;">Family name</label>
    <input class="cf_inputbox required validate-alpha" maxlength="150" size="35" title="Required" id="text_2" name="familyname" type="text" />
  
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 150px;">First name</label>
    <input class="cf_inputbox required validate-alpha" maxlength="150" size="35" title="Required" id="text_3" name="Firstname" type="text" />
  
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 150px;">E-mail</label>
    <input class="cf_inputbox required validate-email" maxlength="150" size="35" title="Invalid" id="text_4" name="Email" type="text" />
  
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_dropdown">
    <label class="cf_label" style="width: 150px;">Country</label>
    <select class="cf_inputbox validate-selection" id="select_5" size="1" title=""  name="Country">
    <option value="">Choose Option</option>
      <option value="China">China</option>
<option value="Japan">Japan</option>
<option value="Korea">Korea</option>
<option value="Taiwan">Taiwan</option>
<option value="Other">Other</option>

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

<div class="form_item">
  <div class="form_element cf_dropdown">
    <label class="cf_label" style="width: 150px;">Contact</label>
    <select class="cf_inputbox validate-selection" id="select_6" size="1" title=""  name="Contact">
    <option value="">Choose Option</option>
      <option value="S.I.E.N.S.">S.I.E.N.S.</option>
<option value="Carmel College">Carmel College</option>
<option value="Rosmini College">Rosmini College</option>
<option value="St Mary's School">St Mary's School</option>

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

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 150px;">Subject</label>
    <input class="cf_inputbox required" maxlength="150" size="35" title="Required" id="text_7" name="Subject" type="text" />
  
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textarea">
    <label class="cf_label" style="width: 150px;">Message</label>
    <textarea class="cf_inputbox required" rows="3" id="text_7" title="Required" cols="45" name="Message"></textarea>
    
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_captcha">
    <label class="cf_label" style="width: 150px;">Enter Code</label>
    <span>{imageverification}</span> 
    
    </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_button">
    <input value="Submit" name="button_9" type="submit" />
  </div>
  <div class="cfclear"> </div>
</div>


My PHP code
<?php
$contact=JRequest::getString('Contact','','post');
$emails= array (
    'S.I.E.N.S.' => 'email@general.school.nz',
    'Carmel College' => 'email@school3.nz',
    'Rosmini College' => 'email@school2.nz',
    'St Mary's School' => 'email@school3.nz'
);
$email_to_use = $email[$contact];
JRequest::setVar('email_to_use',$email_to_use);
?>


My e-mail setup as follows
[attachment=0]emailsetup.JPG[/attachment]

And my Debug code:
Form passed first SPAM check OK
Form passed the submissions limit (if enabled) OK
Form passed the Image verification (if enabled) OK
Form passed the server side validation (if enabled) OK
$_POST Array: Array ( [Title] => Dr [familyname] => Smith [Firstname] => Fed [Email] => andre.basel@gmail.com [Country] => Taiwan [Contact] => Carmel College [Subject] => Test 888 [Message] => Test [chrono_verification] => J6mWv [button_9] => Submit [d55425f16b1479a47289e4b0972722cc] => 1 [1cf1] => b8a57c7cc51a4028df09c66372e7e927 [chronoformname] => form_ContactUs )
$_FILES Array: Array ( )
Form passed the plugins step (if enabled) OK
An email has been SENT successfully from (Smith)xxxx@gmail.com to
An email has been SENT successfully from (S.I.E.N.S.)no-reply@siens.ac.nz to xxxx@gmail.com
Debug End


As you will see "email_to_use" is not getting a value
GreyHead 18 Nov, 2010
Hi rcadmin,


The quote in Mary's here'St Mary's School' => [email]'email@school3.nz[/email]'will break the PHP. It needs to be escaped Mary\'s . . . but even so I wouldn't use these long values. Instead use simple codes for the drop-down values
<option value="siens">S.I.E.N.S.</option>
<option value="carmel">Carmel College</option>
<option value="rosmini">Rosmini College</option>
<option value="st_marys">St Mary's School</option>
and the same in the look-up array
$emails = array (
    'siens' => 'email@general.school.nz',
    'carmel' => 'email@school3.nz',
    'rosmini' => 'email@school2.nz',
    'st_marys' => 'email@school3.nz'
);


I strongly recommend that you do *not* use the Dynamic From Email element in your Email Setups. Using this often results in your emails being marked as spam and dropped into a spam filter. Instead use the static From Email with an address that matches the site domain name and use Dynamic ReplyTo Email for the user email. The result is the same but with a much better chance of good delivery.

Bob
rcadmin 18 Nov, 2010
Hi, done all those changes, including removing the dynamic from e-mail.

But as you see the e-mail address is still not being set.

Form passed first SPAM check OK
Form passed the submissions limit (if enabled) OK
Form passed the Image verification (if enabled) OK
Form passed the server side validation (if enabled) OK
$_POST Array: Array ( [Title] => Mrs [familyname] => Smith [Firstname] => June [Email] => [email]mem455@gmail.com[/email] [Country] => China [Contact] => rosmini [Subject] => Test Rosmini [Message] => Test message for Rosmini [chrono_verification] => J7MTh [button_9] => Submit [3759aa9b60e8a3595579541e35addd57] => 1 [1cf1] => e49200d72adbe59bb90c9ccbb87a2e7e [chronoformname] => form_ContactUs )
$_FILES Array: Array ( )
Form passed the plugins step (if enabled) OK
An email has been SENT successfully from (Smith)info@siens.ac.nz to
An email has been SENT successfully from (S.I.E.N.S.)no-reply@siens.ac.nz to [email]mem455@gmail.com[/email]
Debug End



<?php
$contact=JRequest::getString('Contact','','post');
$emails= array (
    'siens' => 'xxxx@x.school.nz',
    'carmel' => 'xxxx@xx.school.nz',
    'rosmini' => 'xxxx@xxx.school.nz',
    'st_marys' => 'xxxx@xxxx.school.nz'
);
$email_to_use = $email[$contact];
JRequest::setVar('email_to_use',$email_to_use);
?>


Following the steps:
[Contact] => rosmini
Therefore $emails[$contact] = [email]xxxx@xxx.school.nz[/email]
Therefore $email_to_use = [email]xxxx@xxx.school.nz[/email]

There must be something wrong with my JRequest but I can't see it.


Aaaagh after reading the preview for the 3rd time (before submitting) I noticed that I had left the 's' off $e-mail in $email_to_use = $email[$contact]; (should have been $email_to_use = $emails[$contact];)

But glad for this post anyway as I leant a heap :-) Thanks Bob.
GreyHead 19 Nov, 2010
Hi rcadmin,

A little typo has crept in - the array is called $emails but this line is missing the s
$email_to_use = $email[$contact];

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