soycharliente Posted February 23, 2007 Share Posted February 23, 2007 I'm looking to build a contact form with a drop-down menu for different recipients of the form. Does anyone know of a good tutorial for how to integrate PHP with drop-down menus or a site that explains this type of situation? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/39815-solved-contact-form-with-drop-down-menu/ Share on other sites More sharing options...
JBS103 Posted February 23, 2007 Share Posted February 23, 2007 Well any general form tutorial will do what you need. In this case, you would build a completely normal drop down box in the HTML, then on the PHP end you would have it check what the user selected, then send. Take a look at this: http://www.tizag.com/phpT/examples/formex.php Quote Link to comment https://forums.phpfreaks.com/topic/39815-solved-contact-form-with-drop-down-menu/#findComment-192316 Share on other sites More sharing options...
soycharliente Posted February 23, 2007 Author Share Posted February 23, 2007 I know how to build forms. I guess I'm just unsure how to pass the recipient to the PHP. Is it as simple as posting the value and then if statements to see who got posted? Quote Link to comment https://forums.phpfreaks.com/topic/39815-solved-contact-form-with-drop-down-menu/#findComment-192321 Share on other sites More sharing options...
JBS103 Posted February 23, 2007 Share Posted February 23, 2007 Click onto the next page, if I glanced at it correctly, it has the back end for it. If this particular site doesn't do it for you, there are plenty more, just do a quick Google search for "php forms" and you will get plenty. Quote Link to comment https://forums.phpfreaks.com/topic/39815-solved-contact-form-with-drop-down-menu/#findComment-192323 Share on other sites More sharing options...
roopurt18 Posted February 23, 2007 Share Posted February 23, 2007 You don't want to do anything like this: form_handler.php <?php $sel = $_POST['selected']; if($sel == "Bob"){ // Do bob stuff }else if($sel == "Sally"){ // Do sally stuff }else if($sel == "Fred"){ // Do fred stuff } // ...and so on. ?> It's very inefficient, tedious to type, and impossible to maintain. Instead set the value attribute of the form options to an appropriate value, such as the e-mail address of the recipient. form <select name="recipient"> <option value="bob@co.com">Bob</option> <option value="sally@co.com">Sally</option> <option value="fred@co.com">Fred</option> </select> form_handler.php <?php $email = $_POST['recipient']; mail($email, "Hi2u", "Hello, World!"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/39815-solved-contact-form-with-drop-down-menu/#findComment-192325 Share on other sites More sharing options...
redarrow Posted February 23, 2007 Share Posted February 23, 2007 try this ok . <?php $db=mysql_connect("localhost","username","password"); mysql_select_db("database_name",$db); $query="select * form what_ever where email='$email'"; $result=mysql_fetch_assoc($query); echo"<form='method='POST' action=''> <option name='email'>"; while($x=mysql_fetch_assoc($result)){ echo"<option value='".$x['email']."'>".$x['email']."</option>"; } echo"<input type='submit' name='submit' value='email members'></select> </form></option>"; if($_POST['submit']){ $to = $email; $subject = 'hi it redarrow!'; $message = '<b>yo</b>, how are you mate'; $headers = "From: redarrow@what_ever.com\r\n" . 'X-Mailer: PHP/' . phpversion() . "\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: text/html; charset=utf-8\r\n" . "Content-Transfer-Encoding: 8bit\r\n\r\n"; if(mail($to, $subject, $message, $headers)){ echo " cheers email sent to: $email "; } }else{ echo" sorry no email sent"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/39815-solved-contact-form-with-drop-down-menu/#findComment-192352 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.