kristenju Posted October 1, 2009 Share Posted October 1, 2009 I will like to get this output in my email: Dynamite Traffic: Busy Promotions: Buy 1 get 2nd one half price Other comments: They got new merchandise Gap Traffic: Quiet Promotions: Hoodies for $20 Other comments: Window has changed! Here is the part of my form where it contains those form fields (HTML form page): <div> <table width="520" cellpadding="5" cellspacing="0"> <tr><td class="left"> <h3 class="subhead">Dynamite</h3><input style="display:none" class="mainForm" name="comp[]" value="Dynamite"></td> <td></td></tr> <tbody id="fieldBox_16"> <tr><td class="left"> <label class="formFieldQuestion">Traffic:</label></td> <td class="right"> <span><input class="mainForm" type="checkbox" name="traffic[]" id="field_16_option_1" value="very busy" ><label class="formFieldOption" for="field_16_option_1">very busy</label><input class="mainForm" type="checkbox" name="traffic[]" id="field_16_option_2" value="busy" ><label class="formFieldOption" for="field_16_option_2">busy</label><input class="mainForm" type="checkbox" name="traffic[]" id="field_16_option_3" value="Quiet" ><label class="formFieldOption" for="field_16_option_3">Quiet</label></span> </td></tr> </tbody> <tbody id="fieldBox_17"> <tr><td class="left"> <label class="formFieldQuestion">Promotions:</label></td> <td class="right"><textarea id="field_17" class="mainForm" rows="5" cols="30" name="promo[]"></textarea> </td></tr></tbody> <tbody id="fieldBox_18"> <tr><td class="left"><label class="formFieldQuestion">Other comments:</label> </td><td class="right"><textarea id="field_18" class="mainForm" rows="5" cols="30" name="comments[]"></textarea> </td></tr></tbody> <tbody> <tr><td></td></tr> <tr><td class="left"> <h3 class="subhead">Guess</h3><input style="display:none" class="mainForm" name="comp[]" value="Guess"></td> <td></td></tr> <tbody id="fieldBox_16"> <tr><td class="left"> <label class="formFieldQuestion">Traffic:</label></td> <td class="right"> <span><input class="mainForm" type="checkbox" name="traffic[]" id="field_16_option_1" value="very busy" ><label class="formFieldOption" for="field_16_option_1">very busy</label><input class="mainForm" type="checkbox" name="traffic[]" id="field_16_option_2" value="busy" ><label class="formFieldOption" for="field_16_option_2">busy</label><input class="mainForm" type="checkbox" name="traffic[]" id="field_16_option_3" value="Quiet" ><label class="formFieldOption" for="field_16_option_3">Quiet</label></span> </td></tr> </tbody> <tbody id="fieldBox_17"> <tr><td class="left"> <label class="formFieldQuestion">Promotions:</label></td> <td class="right"><textarea id="field_17" class="mainForm" rows="5" cols="30" name="promo[]"></textarea> </td></tr></tbody> <tbody id="fieldBox_18"> <tr><td class="left"><label class="formFieldQuestion">Other comments:</label> </td><td class="right"><textarea id="field_18" class="mainForm" rows="5" cols="30" name="comments[]"></textarea> </td></tr></tbody> <tbody> <tr><td></td></tr> <tr><td class="left"> <h3 class="subhead">Gap</h3><input style="display:none" class="mainForm" name="comp[]" value="Gap"></td> <td></td></tr> <tbody id="fieldBox_16"> <tr><td class="left"> <label class="formFieldQuestion">Traffic:</label></td> <td class="right"> <span><input class="mainForm" type="checkbox" name="traffic[]" id="field_16_option_1" value="very busy" ><label class="formFieldOption" for="field_16_option_1">very busy</label><input class="mainForm" type="checkbox" name="traffic[]" id="field_16_option_2" value="busy" ><label class="formFieldOption" for="field_16_option_2">busy</label><input class="mainForm" type="checkbox" name="traffic[]" id="field_16_option_3" value="Quiet" ><label class="formFieldOption" for="field_16_option_3">Quiet</label></span> </td></tr> </tbody> <tbody id="fieldBox_17"> <tr><td class="left"> <label class="formFieldQuestion">Promotions:</label></td> <td class="right"><textarea id="field_17" class="mainForm" rows="5" cols="30" name="promo[]"></textarea> </td></tr></tbody> <tbody id="fieldBox_18"> <tr><td class="left"><label class="formFieldQuestion">Other comments:</label> </td><td class="right"><textarea id="field_18" class="mainForm" rows="5" cols="30" name="comments[]"></textarea> </td></tr></tbody> <tbody> <tr><td></td></tr> </table></div> This is where I am having problems with in my process.php: $tra = $_POST['traffic'][0].",". $_POST['traffic'][1].",". $_POST['traffic'][2]; for($i = 0; $i < count($_POST['comp']); $i++) { echo $_POST['comp'][$i] ; } $comp .= $_POST['comp'][$i] ; foreach($_POST["comments"] as $value) { $comments .= "$value\n"; } foreach($tra as $value) { $traffic .= "$value\n"; } foreach($_POST["promo"] as $value) { $promo .= "$value\n"; } $traf .= "Achalandage de la boutique: $traffic \n"; $prom .= "Promotions en cours: $promo \n"; $com .= "Remarques pertinentes: $comments \n"; $analyse .="$comp $traf $prom $com"; // email $to = "tam.kristen@gmail.com" ; $subject = "Rapport Journalier: $inputdate"; $message = " <html><body> <b>Competitor Analysis Feedbacks</b> $analyse </body></html>" ; $headers = "From: $store <$storemail>" . "\r\n" . "Reply-To: $store <$storemail>" . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $header); Then I get an error in my thankyou page saying: DynamiteGapGuess Warning: Invalid argument supplied for foreach() in /public_html/report/process.php on line 41 And this is what it is actual displaying in my email when I get the results: Competitor Analysis Feedbacks Traffic: Promotions: Buy 1 get 2nd one half price Hoodies for $20 Why is the store name not displaying? Why is the traffic values not displaying? Why is the 'Comments:' and its values not displaying? Why are they not grouped with the store? Another problem is: I am not seeing the From: email correctly. I have put it as no-reply@xxx.com Please help! Quote Link to comment https://forums.phpfreaks.com/topic/176134-solved-php-email-form-with-array/ Share on other sites More sharing options...
redarrow Posted October 1, 2009 Share Posted October 1, 2009 look at my sig will help you? Quote Link to comment https://forums.phpfreaks.com/topic/176134-solved-php-email-form-with-array/#findComment-928145 Share on other sites More sharing options...
kristenju Posted October 2, 2009 Author Share Posted October 2, 2009 This one: http://simpleforum.ath.cx/mail2.inc ? Quote Link to comment https://forums.phpfreaks.com/topic/176134-solved-php-email-form-with-array/#findComment-929138 Share on other sites More sharing options...
kristenju Posted October 2, 2009 Author Share Posted October 2, 2009 look at my sig will help you? Hi! Your sig is about the mailing part, but I am having problems with my array.. the info doesn't seem to be displaying properly, and some does not appear at all.. Quote Link to comment https://forums.phpfreaks.com/topic/176134-solved-php-email-form-with-array/#findComment-929139 Share on other sites More sharing options...
mikesta707 Posted October 2, 2009 Share Posted October 2, 2009 well firstly this snippet foreach($_POST["comments"] as $value) { $comments .= "$value\n"; } is incorrect. you cannot concatenate things onto a string with no value. if you want to concatenate stuff to that string, you need to give it a value first (even an empty value); $comments = ""; foreach($_POST["comments"] as $value) { $comments .= "$value\n"; } the same idea goes for your $traffic and $promo variables Quote Link to comment https://forums.phpfreaks.com/topic/176134-solved-php-email-form-with-array/#findComment-929144 Share on other sites More sharing options...
kristenju Posted October 3, 2009 Author Share Posted October 3, 2009 Thanks! Now the values are displaying, but I'm still having problems grouping the answers together.. Quote Link to comment https://forums.phpfreaks.com/topic/176134-solved-php-email-form-with-array/#findComment-929450 Share on other sites More sharing options...
cags Posted October 3, 2009 Share Posted October 3, 2009 Another problem is: I am not seeing the From: email correctly. I have put it as no-reply@xxx.com Erm.. No you haven't... $headers = "From: $store <$storemail>" . "\r\n" . What do you mean by grouping? Can you give an example of what your getting, and what you want. Quote Link to comment https://forums.phpfreaks.com/topic/176134-solved-php-email-form-with-array/#findComment-929592 Share on other sites More sharing options...
kristenju Posted October 3, 2009 Author Share Posted October 3, 2009 Another problem is: I am not seeing the From: email correctly. I have put it as no-reply@xxx.com Erm.. No you haven't... $headers = "From: $store <$storemail>" . "\r\n" . What do you mean by grouping? Can you give an example of what your getting, and what you want. I want the output to come out like this: (group or sort by count ([])...?) Dynamite Traffic: busy Promotions: promo1 Comments: comment1 Gap Traffic: quiet Promotions: promo2 Comments: comments2 Right now it is grouped by fieldname ... Dynamite Gap Traffic: busy quiet Promotions: promo1 promo2 Comments: comments 1 comments 2 Quote Link to comment https://forums.phpfreaks.com/topic/176134-solved-php-email-form-with-array/#findComment-929671 Share on other sites More sharing options...
kristenju Posted October 3, 2009 Author Share Posted October 3, 2009 Another problem is: I am not seeing the From: email correctly. I have put it as no-reply@xxx.com Erm.. No you haven't... $headers = "From: $store <$storemail>" . "\r\n" . There is a hidden field in my html file and the value is $store = Store Name $storemail = no-reply@xxx.com I had to do it this way because I would like to use one process page for multiple forms.. Quote Link to comment https://forums.phpfreaks.com/topic/176134-solved-php-email-form-with-array/#findComment-929674 Share on other sites More sharing options...
cags Posted October 3, 2009 Share Posted October 3, 2009 There is a hidden field in my html file and the value is $store = Store Name $storemail = no-reply@xxx.com I had to do it this way because I would like to use one process page for multiple forms.. Ahh ok fair enough. Am I right in saying that the stores will be dynamically generated and there won't just be the few you have in your current HTML? The only reason I ask is the way your are storing some information with the HTML structure is going to make it difficult to achieve the aim you have. What is the objective of the Traffic checkboxes, is it actually possible for a single store to have multiple values? Quote Link to comment https://forums.phpfreaks.com/topic/176134-solved-php-email-form-with-array/#findComment-929686 Share on other sites More sharing options...
kristenju Posted October 3, 2009 Author Share Posted October 3, 2009 Hi! Well basically each of my stores have designated competitors to visit.. so basically they need to do a small report on their traffic, promos and other comments.. So each store has their own form to fill out and submit. (They are different in terms of competitors..) That's why I need all these arrays.... sample of my form: http://www.foxyjeans.com/report/form102.html Quote Link to comment https://forums.phpfreaks.com/topic/176134-solved-php-email-form-with-array/#findComment-929696 Share on other sites More sharing options...
cags Posted October 3, 2009 Share Posted October 3, 2009 Ok, I see the objective, I think life may be a touch easier if we can modify some of the names in the HTML, would this be a problem? Quote Link to comment https://forums.phpfreaks.com/topic/176134-solved-php-email-form-with-array/#findComment-929705 Share on other sites More sharing options...
kristenju Posted October 3, 2009 Author Share Posted October 3, 2009 No prob I just want it to work Quote Link to comment https://forums.phpfreaks.com/topic/176134-solved-php-email-form-with-array/#findComment-929732 Share on other sites More sharing options...
cags Posted October 3, 2009 Share Posted October 3, 2009 Ok... Assuming that all the traffic selections are type="radio" and have a name="traffic_X", where the x represents the index of that shop (from 0 upwards) as you walk down the page.... $feedback = ''; foreach($_POST["comments"] $as $k=>$v) { $feedback .= $_POST['comp'][$k] . "\r\n"; $feedback .= "Traffic: " . $_POST['traffic_' . $k] . "\r\n"; $feedback .= "Promo: " . $_POST["promo"][$k] . "\r\n"; $feedback .= "Comments: " . $_POST["com"][$k] . "\r\n\r\n"; } Note: It does somewhat rely on all fields being required, which you would have to check generating this information. If thats a problem let me know. Quote Link to comment https://forums.phpfreaks.com/topic/176134-solved-php-email-form-with-array/#findComment-929756 Share on other sites More sharing options...
kristenju Posted October 3, 2009 Author Share Posted October 3, 2009 but i thought radio buttons do not work in arrays because buttons only allow one answer and the fact that it uses the same field name... Quote Link to comment https://forums.phpfreaks.com/topic/176134-solved-php-email-form-with-array/#findComment-929821 Share on other sites More sharing options...
cags Posted October 3, 2009 Share Posted October 3, 2009 well I assuming my translation is correct, only 1 of these can be true of any one location? (Très Occupé, OccupéPeu, Occupé, Tranquille), with that being the case you give them all the same name for each shop, then whichever one is selected will be the value for that location. Quote Link to comment https://forums.phpfreaks.com/topic/176134-solved-php-email-form-with-array/#findComment-929837 Share on other sites More sharing options...
kristenju Posted October 3, 2009 Author Share Posted October 3, 2009 But that's the problem.. They have to do a list.. Maybe I didn't explain it clearly enough.. The form you see form102.html is only the form of my store #1. I still have store #2 and #3 and #4... etc.. That list (Forever21, Dynamite, Garage, ...) they are all the competitors, and they need to go in each of the stores and give me feedbacks. So for example how's the traffic at Forever21? Busy How's Traffic at Dynamite? Quiet How's Traffic at Garage? Soso So basically if I put radio buttons instead of checkboxes, they will be selecting busy at forever21, then when they select quiet at Dynamite, the answer of forever21 will automatically be taken off.. because only one value can be working.. So I don't have any problems using checkboxes And even the reply address and from address can be fixed easily. My biggest problem is the answers.. I don't get them the way it's suppose to be.. like.. which should be: $comp[0] Traffic: $traffic[0] Promos: $promo[0] Comments: $comments [0] $comp[1] Traffic: $traffic[1] Promos: $promo[1] Comments: $comments [1] $comp[2] Traffic: $traffic[2] Promos: $promo[2] Comments: $comments[2] But now it is displaying $comp[0] $comp[1] $comp[2] Traffic: $traffic[0] $traffic[1] $traffic[2] Promos: $promo[0] $promo[1] $promo[2] Comments: $comments[0] $comments[1] $comments[2] .... But I haven't tried what you told me to do yet.. let me try it with the checkboxes.. Let me know if you have other suggestions.. Quote Link to comment https://forums.phpfreaks.com/topic/176134-solved-php-email-form-with-array/#findComment-929867 Share on other sites More sharing options...
cags Posted October 3, 2009 Share Posted October 3, 2009 I dont think you understand my code/suggestion. At one shop, so on one HTML page, lets say the local competitors are Forever21 Dynamite and Garage... your HTML would look like so.... <!-- start of form --> <!-- start details for Forever21 --> <input type="radio" name="traffic_0" value="quite" /> <input type="radio" name="traffic_0" value="not-so-quite" /> <input type="radio" name="traffic_0" value="busy" /> <input type="radio" name="traffic_0" value="omg-I-couldnt-move" /> <!-- rest of info for this shop --> <!-- start details of Dynamite --> <input type="radio" name="traffic_1" value="quite" /> <input type="radio" name="traffic_1" value="not-so-quite" /> <input type="radio" name="traffic_1" value="busy" /> <input type="radio" name="traffic_1" value="omg-I-couldnt-move" /> <!-- rest of info for this shop --> <!-- start details of Garage --> <input type="radio" name="traffic_2" value="quite" /> <input type="radio" name="traffic_2" value="not-so-quite" /> <input type="radio" name="traffic_2" value="busy" /> <input type="radio" name="traffic_2" value="omg-I-couldnt-move" /> <!-- rest of info for this shop --> This way, the number that follows traffic_ will match the index of each of the other arrays that a shops details are stored in, because garages comments will be in $_POST['comm'][2]. As I said it only works if each field is required, but I imagine that you would want all forms filling out. So checkboxes would both completely screw up the system, and would be semantically wrong, because you only ever want one value per shop. Quote Link to comment https://forums.phpfreaks.com/topic/176134-solved-php-email-form-with-array/#findComment-929894 Share on other sites More sharing options...
kristenju Posted October 3, 2009 Author Share Posted October 3, 2009 So I should be prenaming them as a number first. should I do that for the other fields, or can I just leave them blank? Quote Link to comment https://forums.phpfreaks.com/topic/176134-solved-php-email-form-with-array/#findComment-929910 Share on other sites More sharing options...
cags Posted October 3, 2009 Share Posted October 3, 2009 The other fields need to be left as is, so that they form an array. It's on that basis that my code works. Your code should looks something like.... <tbody> <tr> <td class="left"><span class="subhead">Analyse de la compétition</span></td> </tr> </tbody> <tbody> <tr> <td class="left"><h3 class="subhead">Forever21</h3> <input style="display: none;" class="mainForm" name="comp[]" value="Forever21"></td> <td></td> </tr> </tbody> <tbody id="fieldBox_16"> <tr> <td class="left"><label class="formFieldQuestion">Achalandage de la boutique:</label></td> <td class="right"><span> <input class="mainForm" name="traffic_0" id="field_16_option_1" value="Très Occupé" type="radio"> <label class="formFieldOption" for="field_16_option_1">Très Occupé</label> <input class="mainForm" name="traffic_0" id="field_16_option_2" value="Occupé" type="radio"> <label class="formFieldOption" for="field_16_option_2">Occupé</label> <input class="mainForm" name="traffic_0" id="field_16_option_3" value="Peu Occupé" type="radio"> <label class="formFieldOption" for="field_16_option_3">Peu Occupé</label> <input class="mainForm" name="traffic_0" id="field_16_option_4" value="Tranquille" type="radio"> <label class="formFieldOption" for="field_16_option_4">Tranquille</label> </span></td> </tr> </tbody> <tbody id="fieldBox_17"> <tr> <td class="left"><label class="formFieldQuestion">Promotions en cours:</label></td> <td class="right"><textarea id="field_17" class="mainForm" rows="5" cols="30" name="promo[]"></textarea></td> </tr> </tbody> <tbody id="fieldBox_18"> <tr> <td class="left"><label class="formFieldQuestion">Remarques pertinentes:</label></td> <td class="right"><textarea id="field_18" class="mainForm" rows="5" cols="30" name="comments[]"></textarea></td> </tr> </tbody> <tbody> <tr> <td><br></td> </tr> </tbody> <tbody> <tr> <td class="left"><h3 class="subhead">Dynamite</h3> <input style="display: none;" class="mainForm" name="comp[]" value="Dynamite"></td> <td></td> </tr> </tbody> <tbody id="fieldBox_16"> <tr> <td class="left"><label class="formFieldQuestion">Achalandage de la boutique:</label></td> <td class="right"><span> <input class="mainForm" name="traffic_1" id="field_16_option_1" value="Très Occupé" type="radio"> <label class="formFieldOption" for="field_16_option_1">Très Occupé</label> <input class="mainForm" name="traffic_1" id="field_16_option_2" value="Occupé" type="radio"> <label class="formFieldOption" for="field_16_option_2">Occupé</label> <input class="mainForm" name="traffic_1" id="field_16_option_3" value="Peu Occupé" type="radio"> <label class="formFieldOption" for="field_16_option_3">Peu Occupé</label> <input class="mainForm" name="traffic_1" id="field_16_option_4" value="Tranquille" type="radio"> <label class="formFieldOption" for="field_16_option_4">Tranquille</label> </span></td> </tr> </tbody> As taken from your actual site and updated... Quote Link to comment https://forums.phpfreaks.com/topic/176134-solved-php-email-form-with-array/#findComment-929918 Share on other sites More sharing options...
kristenju Posted October 3, 2009 Author Share Posted October 3, 2009 I am getting an error though.. actually... in the php part, $feedback = ''; foreach($_POST['comments'] as $k=>$v) { $feedback .= $_POST['comp'][$k] . "\r\n"; $feedback .= "Traffic: " . $_POST['traffic_' . $k] . "\r\n"; $feedback .= "Promo: " . $_POST["promo"][$k] . "\r\n"; $feedback .= "Comments: " . $_POST["com"][$k] . "\r\n\r\n"; } But shouldn't it be: $feedback .= "Comments: " . $_POST["comments"][$k] . "\r\n\r\n"; Cause in my html Comments fieldname is 'comments'... Then where does foreach($_POST['comments'] as $k=>$v) this comments comes from? what should I be replacing it by? Quote Link to comment https://forums.phpfreaks.com/topic/176134-solved-php-email-form-with-array/#findComment-929932 Share on other sites More sharing options...
kristenju Posted October 3, 2009 Author Share Posted October 3, 2009 And It is displayed in my email None of the fields are showing.. Quote Link to comment https://forums.phpfreaks.com/topic/176134-solved-php-email-form-with-array/#findComment-929933 Share on other sites More sharing options...
cags Posted October 3, 2009 Share Posted October 3, 2009 Yes, quite right it does want to be comments, just a typo. Forget the e-mail untill it's working perfectly, just directly after the for each echo out $feedback, and see what gets printed out. Quote Link to comment https://forums.phpfreaks.com/topic/176134-solved-php-email-form-with-array/#findComment-929938 Share on other sites More sharing options...
kristenju Posted October 3, 2009 Author Share Posted October 3, 2009 but.. we are only getting all the results by email.. not on a database server.. Quote Link to comment https://forums.phpfreaks.com/topic/176134-solved-php-email-form-with-array/#findComment-929941 Share on other sites More sharing options...
cags Posted October 3, 2009 Share Posted October 3, 2009 What does that have to do with anything? We are writting a script to process a HTML form and e-mail the details. There is really no point in worrying about sending an e-mail untill we know the processsing is working correctly. If when we echo out $feedback it contains all the correct information. We slap it into an e-mail, job done. If you would rather keep e-mailing the result, checking your e-mail, just to check if a values working rather than print it straight to screen then you go right ahead, I'm just trying to make life easier for you. Quote Link to comment https://forums.phpfreaks.com/topic/176134-solved-php-email-form-with-array/#findComment-929944 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.