Lexi Posted September 10, 2009 Share Posted September 10, 2009 Hi there I know only a tiny bit of php which I have gleened from reviewing scripts online. A few years ago a friend (who I cannot reach) wrote me a very simple script to email form results which I have been modifying over the years for different purposes. At the moment, I am trying to make a very simple script for my Dad's company and unfortunately, I think I have been away from web design and php for too many years! My query is similar to a topic from 2007 titled "[sOLVED] PHP Form Processor and Checkbox array help " but I am having no luck getting my script to work. The form is quite lengthy so I have only included the code here that my problem pertains to. If you need to know more, just ask. Form: <td colspan="2" valign="top"><p id="content">Request Information on Products:</p></td> </tr> <tr> <td valign="top"> </td> <td colspan="2" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="25%"><input name="ProductInfo[]" type="checkbox" class="radio" value="EVS3" tabindex="18" /> Flir EVS3™</td> <td width="25%"><input name="ProductInfo[]" type="checkbox" class="radio" value="Product 2" tabindex="18" /> Product 2 </td> <td width="25%"> </td> <td width="25%"> </td> </tr> </table></td> </tr> <tr> <td colspan="2" valign="top"><p id="content">Request Information on Services:</p></td> </tr> <tr> <td valign="top"> </td> <td colspan="2" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="25%"><p> <input name="ServiceInfo[]" type="checkbox" class="radio" value="Scheduled Maintenance" tabindex="19" /> Scheduled Maintenance </p> <p></p></td> <td width="25%"><input name="ServiceInfo[]" type="checkbox" class="radio" value="Uncscheduled Maintenace" tabindex="20" /> Unscheduled Maintenance</td> <td width="25%"><input name="ServiceInfo[]" type="checkbox" class="radio" value="Custom Maintenance Plan" tabindex="21" /> Custom Maintenance Plan</td> <td width="25%"> </td> </tr> <tr> <td><input name="ServiceInfo[]" type="checkbox" class="radio" value="Aircraft Procurement" tabindex="22" /> Aircraft Procurement</td> <td><input name="ServiceInfo[]" type="checkbox" class="radio" value="Misc. Product Procurement" tabindex="23" /> Misc. Product Procurement </td> <td><input name="ServiceInfo[]" type="checkbox" class="radio" value="Misc. Product Installation" tabindex="24" /> Misc. Product Isnstallation</td> <td> </td> </tr> And here is the php on the results page... <?php //grab variables from the HTML form $name = $_POST["Name"] ; $jobtitle = $_POST["JobTitle"] ; $company = $_POST["Company"] ; $city = $_POST["City"] ; $provstate = $_POST["ProvState"] ; $country = $_POST["Country"] ; $phone = $_POST["Phone"] ; $mobile = $_POST["Mobile"] ; $email = $_POST["Email1"] ; $reply = $_POST["ContactBy"] ; $comments = $_POST["Comments"] ; foreach($_POST["ProductInfo"] as $value) { $productinfo = "$value\n"; } foreach($_POST["ServiceInfo"] as $value) { $serviceinfo = "$value\n"; } //print and send email $mailto = "alexis_tanner@hotmail.com"; mail($mailto, "RCChoppers.ca: Contact Form Submission", "You have recieved a query from your web site contact form. ================ Name: $name Job Title: $jobtitle Company: $company Location: $city, $provstate, $country Phone Number: $phone Mobile Number: $mobile E-mail Address: $email Reply by: $reply Requesting information on: $productinfo $serviceinfo Comments: $comments End of form.", "From: $email\nReply-To: $email\n"); ?> What am I doing wrong? I am not sure of the placement of the "foreach" statement, but that is what I was able to gather from the old topic. My form is returning only the last variable checked in replace of the entire array. Results: You have recieved a query from your web site contact form. ================ Name: Alexis Job Title: Company: Location: Burnaby, BC, Canada Phone Number: 123-456-7890 Mobile Number: 123-456-7891 E-mail Address: alexis@test.ca Reply by: Phone Requesting information on: Product 2 Aircraft Procurement Comments: Reset code test. End of form. Please help! I've been working on this all day and having no luck! Thanks in advance. Quote Link to comment Share on other sites More sharing options...
cbolson Posted September 10, 2009 Share Posted September 10, 2009 Hi, you have this: foreach($_POST["ProductInfo"] as $value) { $productinfo = "$value\n"; } The code is looping through the array ok but is then overwriting the $productinfo variable with the $value on each pass. That is why you end up with only the last one. You need to "add" to the variable rather than assign the value. You can do this like this: foreach($_POST["ProductInfo"] as $value) { $productinfo .= "$value\n"; } Simply by adding the "." in there you are now adding to the variable rather than reassigning it. Chris Quote Link to comment Share on other sites More sharing options...
Lexi Posted September 10, 2009 Author Share Posted September 10, 2009 That's it?? I missed a "." ???? ha ha ha. Thanks sooo much! I think I saw that somewhere on the interwebs and had no idea what it was for... So I deleted it in a rewrite. Thanks again! Quote Link to comment Share on other sites More sharing options...
cbolson Posted September 10, 2009 Share Posted September 10, 2009 it is often the simplest of things. Please mark this as solved if that as the case so that we others know not to spend time reading solved questions. Chris 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.