Home | Products | Consulting | Forums | Support | Order | 1-800-752-0455
  Main
Index
Search
Posts
Who's
Online
Log
In

Home: Products: CMS Builder:
Case switching

 

 


terryally
User

Sep 5, 2008, 2:48 AM

Post #1 of 11 (1683 views)
Shortcut
Case switching Can't Post

Hiya,

Need some help.

I am trying to use a switch on a contact form. I am using the multi menu type to populate the dropdown box as illustrated below.


Code
<?php // Select email contact from drop down box ?> 

<select class="inp" size="1" name="emailto">
<option>Select where to send this email enquiry</option>

<?php foreach ($my_contact_directoryRecords as $record): ?>

<option value="<?php echo $record['case'] ?>"><?php echo $record['recipient'] ?></option>
<?php endforeach;?>
</select>


This produces the following:


Code
	 <select class="inp" size="1" name="emailto"> 
<option>Select where to send this email enquiry</option>
<option value="admin">Administration</option>
<option value="accts">Accounts</option>
<option value="cab">Conferences and Banquetting</option>
<option value="events">Private Events & Special Occasions</option>
<option value="res">Reservations</option>
</select>




However my problem comes with the switch. Of course I do not want to reveal the email addresses online so I set up the switch below. I have tried to replicate this unsuccessful and need some assistance.



Code
	$emailto = $_POST['emailto'];  

switch ($emailto) { // select addressee
case "admin":
$recipient = "Administration";
$emailto = "admin@mydomain.com";
break;
case "accts":
$recipient = "Accounts";
$emailto = "accounts@mydomain.com";
break;
case "cab":
$recipient = "Conferences and Banquetting";
$emailto = "conferences@mydomain.com";
break;
case "events":
$recipient = "Private Events & Special Occasions";
$emailto = "events@mydomain.com";
break;
case "res":
$recipient = "Reservations";
$emailto = "reservation@mydomain.com";
break;
default:
echo '<p><font color="red" size="+1">Please select a destination from the drop down box!</font></p>';
}



Dave
Staff / Moderator


Sep 5, 2008, 1:35 PM

Post #2 of 11 (1654 views)
Shortcut
Re: [terryally] Case switching [In reply to] Can't Post

Hi Terry,

What I usually do at this point is print out all my values to make sure they are what I think they are. Try this after your switch code:

print "emailto (from POST) = {$_POST['emailto']}<br/>\n";
print "emailto = $emailto<br/>\n";
print "recipient= $recipient<br/>\n";

Also, don't set $emailTo twice. It's best not to use a variable for two different things. Try this instead:

switch ($_POST['emailto']) { // select addressee

Then you'll only be setting it inside of the switch block.

Let me know if that helps any! :)

Dave Edis - Senior Developer
interactivetools.com


terryally
User

Sep 5, 2008, 2:55 PM

Post #3 of 11 (1650 views)
Shortcut
Re: [Dave] Case switching [In reply to] Can't Post

Hi Dave,

What I have been trying to replicate with the switch is as follows but it is not working:


Code
switch ($emailto) {   // select addressee  

<?php foreach ($my_contact_directoryRecords as $record): ?>

case "echo $record['case'];":
$recipient = "echo $record['recipient'];";
$emailto = "echo $record['emailto'];";
break;
<?php endforeach;?>
default:
echo '<p><font color="red" size="+1">Please select a destination from the drop down box!</font></p>';
}


Basically, if I were writing a MySQL/PHP SELECT/QUERY statement I would while a WHILE loop at that point to populate the switch statement. But with CMS B, I am wondering how to achieve this.

I tried the above but I got an error message.

Terry


Dave
Staff / Moderator


Sep 8, 2008, 11:29 AM

Post #4 of 11 (1119 views)
Shortcut
Re: [terryally] Case switching [In reply to] Can't Post

You can't really generate PHP code with PHP code and then run it (or at least usually you shouldn't).

What are you trying to do? There may be a more direct way. Are you trying to lookup a email address from the database based on a nickname and then use that in an email form?

Dave Edis - Senior Developer
interactivetools.com


terryally
User

Sep 8, 2008, 11:58 AM

Post #5 of 11 (1107 views)
Shortcut
Re: [Dave] Case switching [In reply to] Can't Post

Hi Dave,

Yes, that's exactly what I am trying to do.

Once the "recipient" is selected from the drop down box then I want to have that email sent to the address.

Thinking about it now, I would need to use a WHERE clause, wouldn't I? i.e. WHERE recipient="$record['recipient']" or something to that effect?

Terry


Dave
Staff / Moderator


Sep 8, 2008, 3:30 PM

Post #6 of 11 (1037 views)
Shortcut
Re: [terryally] Case switching [In reply to] Can't Post

Yes, the code would look something like this (untested):


Code
// lookup email alias 
$emailAlias = $_POST['emailto'];
$escapedAlias = mysql_real_escape_string($_POST['emailto']);

list($records) = getRecords(array(
'tableName' => 'yourTableName',
'where' => " recipient = '$escapedAlias' ",
'limit' => 1
));
$record = @$records[0]; // get first record

if (!$record) { die("Couldn't find email for alias '$emailAlias'"); }

print "Recipient: $record['recipient']<br/>\n";
print "Email: $record['emailto']<br/>\n";


Hope that helps!

Dave Edis - Senior Developer
interactivetools.com


terryally
User

Sep 10, 2008, 4:50 AM

Post #7 of 11 (892 views)
Shortcut
Re: [Dave] Case switching [In reply to] Can't Post

Tested and works wonderfully.

Thanks Dave!!


(This post was edited by terryally on Sep 10, 2008, 4:51 AM)


terryally
User

Sep 12, 2008, 2:28 AM

Post #8 of 11 (814 views)
Shortcut
Re: [terryally] Case switching [In reply to] Can't Post

Hi Dave,

I've further tested this.

It works really well as a standalone but when I integrate it into an ISSET statement it does not.

Me thinks that instead of POSTing to the same page I would have to send it to another page for this to work.

I do not have the time right now to experiment as I am on a very tight deadline to deliver three websites but later this month I am going to experiment further since this seems a far better solution than hard coding a case switch. At that time, I will post here again and let you know the outcome.

Cheers
Terry


Dave
Staff / Moderator


Sep 12, 2008, 11:31 AM

Post #9 of 11 (785 views)
Shortcut
Re: [terryally] Case switching [In reply to] Can't Post

Ok great, thanks for posting back! :) Let us know what the outcome is.

Dave Edis - Senior Developer
interactivetools.com


terryally
User

Sep 30, 2008, 10:58 AM

Post #10 of 11 (343 views)
Shortcut
Re: [Dave] Case switching [In reply to] Can't Post


In Reply To


Code
// lookup email alias 
$emailAlias = $_POST['emailto'];
$escapedAlias = mysql_real_escape_string($_POST['emailto']);

list($records) = getRecords(array(
'tableName' => 'yourTableName',
'where' => " recipient = '$escapedAlias' ",
'limit' => 1
));
$record = @$records[0]; // get first record

if (!$record) { die("Couldn't find email for alias '$emailAlias'"); }

print "Recipient: $record['recipient']<br/>\n";
print "Email: $record['emailto']<br/>\n";




Hi Dave,

I've tried but I cannot get the above code integrated and working, so I resorted to writing a query below which does the trick.

Terry



Code
$emailAlias = $_POST['emailto'];  
$escapedAlias = mysql_real_escape_string($_POST['emailto']);


$query = "SELECT * FROM cmsb_lakeside_contact_directory WHERE rcptid='$escapedAlias' LIMIT 1";
$result = mysql_query ($query);
$record = mysql_fetch_array ($result, MYSQL_BOTH);

if (record) {

$sendto = $record;
$recipient = $record[recipient];

}
[/code]
The second last variable is meant to call the 'email' value but your system is stripping my code.


Dave
Staff / Moderator


Oct 1, 2008, 10:52 AM

Post #11 of 11 (330 views)
Shortcut
Re: [terryally] Case switching [In reply to] Can't Post

Wow, looks like you're getting into some pretty advanced PHP there. Nice work! :) Glad to hear it's working now!

Dave Edis - Senior Developer
interactivetools.com

 
 
 


Search for (options)
Products
CMS Builder
Article Manager
Realty Manager
Listings Manager
Order Now
Services
Priority Consulting
Support
Online Documentation
Support Forums
Support Homepage
Company Info
12 reasons to choose us!
Meet the team
Monthly newsletter
Contact Us
Toll Free: 1-800-752-0455
Phone: (604) 689-3347
Sales | Support
Conditions of Use | Privacy Policy | Copyright © interactivetools.com 2008
#201 - 2730 Commercial Drive, Vancouver BC Canada V5N 5P4