DonelleJenae Posted February 25, 2008 Share Posted February 25, 2008 Can someone who knows php please help? I am new to php. After a lot of research, I got my form to work by using some php code, however I know nothing about it and I am not sure what I need to add to make stuff work etc. I have a form mailer script that I created in php and I have an option on my html form that I want users to be able to select multiple options using control+click, however, when I test the form only the first option selected comes to my email inbox. Everything else works how it should, except for that. Here is my code. Do I need to add something in my php to make it work? If so what code to I need to add, where to I add it? <?php $property = $_POST['property']; $cities = $_POST['cities']; $other = $_POST['other']; $min = $_POST['min']; $max = $_POST['max']; $feet = $_POST['feet']; $type = $_POST['type']; $rooms = $_POST['rooms']; $bath = $_POST['bath']; $comments = $_POST['comments']; $email = $_POST['email']; header( "Location: http://www.findourpad.com/thanks.htm" ); $to = "sweez55@comcast.net"; $subject = ";Custom Home Search Results"; $eol="\r\n"; $headers = "From: ". $full_name ." <". $email .">".$eol; $headers .= "Reply-To: ". $full_name." <". $email .">".$eol; $message .= ";Property Type: ". $property . "\n"; $message .= ";Cities: ". $cities."\n"; $message .= ";Other Locations: ". $other . "\n"; $message .= ";Minimum Price: ". $min . "\n"; $message .= ";Maximum Price: ". $max . "\n"; $message .= ";Square Feet: ". $feet . "\n"; $message .= ";Home Type: ". $type . "\n"; $message .= ";Minimum Bedrooms: ". $rooms . "\n"; $message .= ";Minimum Bathrooms: ". $bath . "\n"; $message .= ";Additional Comments: ". $comments . "\n"; $message .= ";Email Address: ". $email . "\n"; foreach($_POST as $k => $v) { if ($v == '') continue; // skip empty fields if($htmlFormat) { $v = str_replace("\n","<br>\n",$v); } if (is_array($v)) { for ($z=0;$z<count($v);$z++) { if($i) { $msg .= "$bl0$k:$ld$v[$z]$el"; } else { $msg .= "$bl1$k:$ld$v[$z]$el"; } $i = !$i; } } else { if($i) { $msg .= "$bl0$k:$ld$v$el"; } else { $msg .= "$bl1$k:$ld$v$el"; } $i = !$i; } } if(mail("$to", "$subject", "$message", "$headers")){ echo "Mail Was Sent, Check Your Junk or Inbox."; }else{ echo "There was an error delivering your message, please try again"; } ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted February 25, 2008 Share Posted February 25, 2008 On a multi option field, you need to use an array to store all the choices they made. Quote Link to comment Share on other sites More sharing options...
DonelleJenae Posted February 25, 2008 Author Share Posted February 25, 2008 I don't know anything about php. What code to I need to add and where on the form do I need to add it. I have my form set up, my variable for my option is named cities, I have 8 or so city selections on a drop down menu for a user to pick from. My php script works just fine, I get my results to my inbox, it directs the user to a thank you page, etc. But when a user selects multiple options, only the first on selected is listed in my results. I don't know what code to add, where to add it, etc. I am a total php newbie and it took me a while to even understand it enough to get this much of it working. Quote Link to comment Share on other sites More sharing options...
DarkerAngel Posted February 25, 2008 Share Posted February 25, 2008 Step 1. Format your <select> as <select name="field_name[]" size="##" multiple> The [] says your submitting an array, Step 2. Your not going to want to see an ugly array line so $field_name = implode(', ', $_POST['field_name']); Therefor if some one selects This option That option Oh and the other option The string will be produced This option, That option, On and the other option Quote Link to comment Share on other sites More sharing options...
DonelleJenae Posted February 25, 2008 Author Share Posted February 25, 2008 Where would I add this in my script. Can you copy my script on my initial post and paste the code in where it should be to show me what it should look like? DO I need to add anything to my form code (html) to make it work with the php? Quote Link to comment Share on other sites More sharing options...
DarkerAngel Posted February 25, 2008 Share Posted February 25, 2008 Okay in your form html what I said above change the <select> so the name tag's contents ends with [] In the php script change whatever that from was from $_POST['name'] to implode(', ', $_POST['name']); replacing name with whatever the form element name was. Quote Link to comment Share on other sites More sharing options...
DonelleJenae Posted February 25, 2008 Author Share Posted February 25, 2008 Okay, I tried that, hopefully I did it right, I will test it and see if it works. Thank you very much. I have asked a ton of people I know how to get this to work and I don't know anyone who knows php that got back to me, I signed up here and posted and I have got more help here so far than anywhere or with anyone else. Quote Link to comment 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.