austin350s10 Posted April 16, 2009 Share Posted April 16, 2009 I have been working on a form for a while now and I am about ready to pull my hair out. The form is in a simple HTML file that uses the POST method to send the field inputs to a PHP file which in-turn "should" send me an email. I have used this PHP set-up in the past and it worked without a glitch. The only thing I have changed this time around is I have added a list that I would like users to pick multiple items from. When the user submits the form I want to get an email with all the selections they made. Right now when you submit the form it will send all the input fields except the list. I know the problem has something to do with arrays but I have no idea how to make it work properly. Below is the HTML and PHP code I am using. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form action="serviceing.php" method="post" NAME="combo_box" ID="combo_box"> <input name="firstname" type="text" id="firstname"/> <input name="lastname" type="text" id="lastname"/> <input name="city" type="text" id="city"/> em<input name="email" type="text" id="email"/> <input name="phone" type="text" id="phone" /> <input name="Cfirstname" type="text" id="Cfirstname" /> <input name="Clastname" type="text" id="Clastname" /> <input name="Ccity" type="text" id="Ccity" /> <input name="state" type="text" id="state" /> <input name="age" type="text" id="age" /> <input name="sex" type="text" id="sex" /> <input name="date" type="text" id="date" /> <input name="type" type="text" id="type" /> <select name="list[]" size="10" multiple id="list"> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> <option>6</option> <option>7</option> <option>8</option> <option>9</option> <option>10</option> <option>11</option> <option>12</option> <option>13</option> <option>14</option> </select> <textarea name="extra" cols="" rows="" id="extra"></textarea> <input name="submit" type="submit" id="submit" value="Submit" /> </form> </body> </html> <?php /*subject and email variables*/ $emailSubject = 'Test'; $webMaster = 'website2@affordablehomecare.org'; /*gathering data variables*/ $firstnameField = $_POST['firstname']; $lastnameField = $_POST['lastname']; $cityField = $_POST['city']; $emailField = $_POST['email']; $phoneField = $_POST['phone']; $CfirstnameField = $_POST['Cfirstname']; $ClastnameField = $_POST['Clastname']; $CcityField = $_POST['Ccity']; $stateField = $_POST['state']; $ageField = $_POST['age']; $sexField = $_POST['sex']; $dateField = $_POST['date']; $typeField = $_POST['type']; $listField = $_POST['list']; $extraField = $_POST['extra']; /*email field*/ $body = <<<EOD <br><hr><br> <h2>Contact Person</h2> <hr> Contact First Name: $firstname <br> Contact Last Name: $lastname <br> Contact City: $city <br> Contact Email: $email <br> Contact Phon Number: $phone <br> <h2>Client Info</h2> <hr> Client First Name: $Cfirstname <br> Client Last Name: $Clastname <br> Client City: $Ccity <br> Client state: $state <br> Client Age: $age <br> Client Sex: $sex <br> Date Service Is Needed: $date <br> Type Of Service: $type <br> Problems: $list <br> Extra Info: $extra <br> EOD; /*email sender script*/ $headers = "From: $ct_email\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($webMaster, $emailSubject, $body, $headers); /*resultes*/ $theResults = <<<EOD <html> <head> <title>Request Submitted</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <p>it works!!!!</p> </body> </html> EOD; echo "$theResults"; ?> ( tags added by kenrbnsn) Quote Link to comment https://forums.phpfreaks.com/topic/154418-simple-html-to-php-form-submit-problems/ Share on other sites More sharing options...
Maq Posted April 16, 2009 Share Posted April 16, 2009 None of your options have values. Please use tags when posting code. Quote Link to comment https://forums.phpfreaks.com/topic/154418-simple-html-to-php-form-submit-problems/#findComment-811924 Share on other sites More sharing options...
soak Posted April 16, 2009 Share Posted April 16, 2009 Whilst not being valid xhtml1 the options should still work. The problem is with the array as the OP mentioned. To get the contents of the array into a string you could do something like: <?php $listString = ''; if (isset($list) && is_array($list)) { $listString = implode(', ', $list); } Then just include the variable $listString in place of $list when building your email body. Quote Link to comment https://forums.phpfreaks.com/topic/154418-simple-html-to-php-form-submit-problems/#findComment-811930 Share on other sites More sharing options...
Maq Posted April 16, 2009 Share Posted April 16, 2009 You also assign $listField but never use it... Quote Link to comment https://forums.phpfreaks.com/topic/154418-simple-html-to-php-form-submit-problems/#findComment-811932 Share on other sites More sharing options...
austin350s10 Posted April 16, 2009 Author Share Posted April 16, 2009 I'm sorry, I forgot to mention that I am about as new as you can get in the wonderful but frustrating world of PHP. I really need to be shown the completed code or at least explain the solution in extremely layman's terms in order for me to really know what I'm doing. Again I am so sorry, and I'm sure you hate people like me that don't even know the basics of this but I have exhausted all my resources and figured it is time to bow down and refer to the experts. Thank You, -Austin- Quote Link to comment https://forums.phpfreaks.com/topic/154418-simple-html-to-php-form-submit-problems/#findComment-811956 Share on other sites More sharing options...
Maq Posted April 16, 2009 Share Posted April 16, 2009 You assign $listField here: $listField = $_POST['list']; But never use it... So let's make it. You have to grab all the values from the array so, you can use what saok suggested and implode it together into a single string: $list = implode(', ', $listField); Also remember to give your options values. i.e.: 1 2 3 etc... Quote Link to comment https://forums.phpfreaks.com/topic/154418-simple-html-to-php-form-submit-problems/#findComment-811960 Share on other sites More sharing options...
austin350s10 Posted April 17, 2009 Author Share Posted April 17, 2009 Oh, that kinda makes since. The only thing I am still unsure of is exactly where that bit of code should go. Would it look something like this? Thanks Again, -Austin- $firstnameField = $_POST['firstname']; $lastnameField = $_POST['lastname']; $cityField = $_POST['city']; $emailField = $_POST['email']; $phoneField = $_POST['phone']; $CfirstnameField = $_POST['Cfirstname']; $ClastnameField = $_POST['Clastname']; $CcityField = $_POST['Ccity']; $stateField = $_POST['state']; $ageField = $_POST['age']; $sexField = $_POST['sex']; $dateField = $_POST['date']; $typeField = $_POST['type']; $list = implode(', ', $listField); $extraField = $_POST['extra']; Quote Link to comment https://forums.phpfreaks.com/topic/154418-simple-html-to-php-form-submit-problems/#findComment-812249 Share on other sites More sharing options...
austin350s10 Posted April 17, 2009 Author Share Posted April 17, 2009 Any ideas on what I am doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/154418-simple-html-to-php-form-submit-problems/#findComment-812522 Share on other sites More sharing options...
Maq Posted April 17, 2009 Share Posted April 17, 2009 See if this works: Untitled Document </pre> <form action="serviceing.php" method="post" name="combo_box" id="combo_box"> em 1 2 3 4 5 6 7 8 9 10 11 12 13 14 </form> <br><br><br><br><br><br>/*subject and email variables*/ <br> $emailSubject = 'Test';<br> $webMaster = 'website2@affordablehomecare.org';<br><br>/*gathering data variables*/<br> $firstnameField = $_POST['firstname'];<br> $lastnameField = $_POST['lastname'];<br> $cityField = $_POST['city'];<br> $emailField = $_POST['email'];<br> $phoneField = $_POST['phone'];<br> $CfirstnameField = $_POST['Cfirstname'];<br> $ClastnameField = $_POST['Clastname'];<br> $CcityField = $_POST['Ccity'];<br> $stateField = $_POST['state'];<br> $ageField = $_POST['age'];<br> $sexField = $_POST['sex'];<br> $dateField = $_POST['date'];<br> $typeField = $_POST['type'];<br> $listField = $_POST['list'];<br> $extraField = $_POST['extra'];<br> $list = implode(', ', $listField);<br> <br><br>/*email field*/<br><br> $body = <br><hr> <br><br><h2>Contact Person</h2> <br><hr> <br>Contact First Name: $firstname <br> <br>Contact Last Name: $lastname <br><br>Contact City: $city <br><br>Contact Email: $email <br><br>Contact Phon Number: $phone <br><br><h2>Client Info</h2> <br><hr> <br>Client First Name: $Cfirstname <br><br>Client Last Name: $Clastname <br><br>Client City: $Ccity <br><br>Client state: $state <br><br>Client Age: $age <br><br>Client Sex: $sex <br><br>Date Service Is Needed: $date <br><br>Type Of Service: $type <br><br>Problems: $list <br><br>Extra Info: $extra <br><br>EOD;<br><br>/*email sender script*/<br> $headers = "From: $ct_email\r\n";<br> $headers .= "Content-type: text/html\r\n";<br> $success = mail($webMaster, $emailSubject, $body, $headers);<br> <br>/*resultes*/<br><br> $theResults = <br><br><title>Request Submitted</title> <br><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <br><br><br><p>it works!!!!</p> <br><br><br>EOD;<br>echo "$theResults";<br><br Quote Link to comment https://forums.phpfreaks.com/topic/154418-simple-html-to-php-form-submit-problems/#findComment-812552 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.