php dropdown

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
asiddle423
Forum Newbie
Posts: 2
Joined: Sun Jan 22, 2006 12:34 pm

php dropdown

Post by asiddle423 »

hawleyjr | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


hi can anyone help me with my php email form, it is to change the email address when selected from a dropdown menu

to view what i have been testing go onto http://www.jarcodesigns.co.uk/contactform.php

currently i have this code

Code: Select all

//from line 139
if ($_POST['Submit'])
{
//set variables
$name = $_POST['name'];
$email = $_POST['email'];
$ip = $_SERVER['REMOTE_ADDR'];
$message = $_POST['message'];

//if-else statements
if ($department[$key] == 1)
{
$emailaddress = 'xxxx1@jarcodesigns.co.uk';
}
else if ($department[$key] == 2)
{
$emailaddress = 'xxxx2@jarcodesigns.co.uk';
}
else if ($department[$key] == 3)
{
$emailaddress = 'xxxx3@jarcodesigns.co.uk';
}
else if ($department[$key] == 4)
{
$emailaddress = 'xxxx4@jarcodesigns.co.uk';
}
else if ($department[$key] == 5)
{
$emailaddress = 'xxxx5@jarcodesigns.co.uk';
}


$subject = "Contact JARCO";
mail($emailaddress, $subject,"Senders Name: $name <p>Senders Mail: $email </p><p>Their Ip: $ip </p><p>Their Message: $message</p>");

echo $emailaddress;
}
else
{
?>


//this then goes through my form layout and reachs my array code
//line 193
<?
$department = array(
1 => "Web Design (Ryan Norton)",
2 => "Multimedia (Joe Groves)",
3 => "Photography (Oliver Brayford)",
4 =>"Scripting (Andrew Siddle)",
5 => "Logo Design (Andrew Figg)",
);
$department = str_replace(" ", " ", $department);

echo '<select name=department>';
foreach($department as $key => $value)
{
echo '<option value='.$value.'> '.$value.'';
}
echo '</select>';
?>
//then the rest is the layout and submitting part of the form

thanks asiddle423


hawleyjr | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

I don't see where you declare the variable: $department
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Also, you REALLY need to validate the data before sending it to the mail() function
asiddle423
Forum Newbie
Posts: 2
Joined: Sun Jan 22, 2006 12:34 pm

Post by asiddle423 »

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


i declare the $department variable here and im going to validate it when iv sorted out this problem

Code: Select all

//this then goes through my form layout and reachs my array code
//line 193
<?
$department = array(
1 => "Web Design (Ryan Norton)",
2 => "Multimedia (Joe Groves)",
3 => "Photography (Oliver Brayford)",
4 =>"Scripting (Andrew Siddle)",
5 => "Logo Design (Andrew Figg)",
);
$department = str_replace(" ", " ", $department);

echo '<select name=department>';
foreach($department as $key => $value)
{
echo '<option value='.$value.'> '.$value.'';
}
echo '</select>';
?>

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

I can't tell that you have said what the problem is? As hawleyjr says, you are testing $department with if's before it is declared. And your if checks are for $department[$key] == 1, but you haven't declared $department or $key that we can tell. Plus, shouldn't that be $department[1] == 'Web Design (Ryan Norton)' or something.

Looking at your actual form online you now have single quotes around the form option labels.
(#10850)
Post Reply