Jump to content

JamesKoash

Members
  • Posts

    23
  • Joined

  • Last visited

JamesKoash's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Actually don't worry... I think it's because I haven't configured my PHP.ini file in Wampserver for testing.
  2. I've built a survey which uses sessions to store user input. Rather than putting this into an SQL database, I've decided to use PHP to email the data as the information isn't private or confidential. Here is my code, following ($_SERVER['REQUEST_METHOD'] == 'POST'): $to = "xyz"; $subject = "Survey Response"; $message = "Test"; $from = "xyz"; $headers = "From:" . $from; mail($to,$subject,$message,$headers); session_destroy(); header('Location: page_6.php'); exit; 'xyz' is obviously where a valid email address needs to go. However, even when I've tried it with a valid email address, nothing seems to be sending. Can someone tell me what I've done wrong? I also tried $message = print_r($_SESSION); but that didn't work either. Thanks
  3. Actually, don't worry... adding the [] back to the end of the name seems to have worked. Thanks.
  4. Hi there cyberRobot Your code is great for radio buttons, but if you look at my original post you'll see two of the form fields use checkboxes, allowing the user to select multiple options. I've just tried your code for checkboxes and it pops up with error: "in_array() expects parameter 2 to be array, string given". My original code works much better for this as it saves the following to session data. I just haven't managed to work out how to add checked="checked" for the options that have been selected. [Marketing Agency] => False [PR Agency] => False [Design Studio] => False [Marketing Consultant] => True [Media Agency] => False [Advertising Agency] => False [Service or Product Design Agency] => False [Customer Experience Agency] => False Thanks
  5. Here is the rest of the code: $outsource2 = array("Marketing Agency","PR Agency","Design Studio","Marketing Consultant", "Media Agency", "Advertising Agency", "Service or Product Design Agency", "Customer Experience Agency"); if($_SERVER['REQUEST_METHOD'] == 'POST') { if(isset($_POST['outsource'])){ foreach($outsource2 as $outsource){ $value = (in_array($outsource,$_POST['outsource']) ? "True" : "False"); $_SESSION[$outsource] = $value; $result[$outsource] = $value; } } else { unset($_SESSION['outsource']); } } Like I said, I just need to know how to add checked="checked" for the options that have been selected. Thanks
  6. Thank you -- just tried that and it seems that I made a minor error with variable names. Another quick question... I want to add checked="checked" to the radio buttons and checkboxes that have been selected. How is this possible? Thanks
  7. Here is my code: $marketingvalueOutput = ""; foreach($marketingimportance2 as $marketingimportance){ $marketingvalueOutput .= "<input type=\"radio\" class=\"radio\" name=\"marketingimportance[]\" value=\"". $marketingimportance ."\">". $marketingimportance ." \r"; } $marketingvalueOutput .= ""; $custexpOutput = ""; foreach($custexp2 as $custexp){ $custexpOutput .= "<input type=\"radio\" class=\"radio\" name=\"custexp[]\" value=\"". $custexp ."\">". $custexp ." \r"; } $custexpOutput .= ""; $marfuOutput = ""; foreach($marfu2 as $marfu){ $marfuOutput .= "<input type=\"radio\" class=\"radio\" name=\"marfu[]\" value=\"". $marfu ."\">". $marfu ." \r"; } $marfuOutput .= "<br />"; $custexpoptionsOutput = ""; foreach($custexpoptions2 as $custexpoptions){ $custexpoptionsOutput .= "<input type=\"checkbox\" class=\"checkbox\" name=\"custexpoptions[]\" value=\"". $custexpoptions ."\">". $custexpoptions ." \r"; } $custexpoptionsOutput .= "<br />"; $outsourceoptionsOutput = ""; foreach($outsource2 as $outsource){ $outsourceoptionsOutput .= "<input type=\"checkbox\" class=\"checkbox\" name=\"outsource[]\" value=\"". $outsource ."\">". $outsource ." \r"; } $outsourceoptionsOutput .= "<br />"; Here are the two errors I'm getting: Warning: Invalid argument supplied for foreach() in C:\wamp\www\survey\page_3.php on line 135 Notice: Undefined variable: custexp2 in C:\wamp\www\survey\page_3.php on line 135 Line 135 is the second foreach loop which says foreach($custexp2 as $custexp). Thanks
  8. I'm getting the following error: Array to string conversion in C:\wamp\www\survey\page_3.php on line 164 Here is my code, which is a slightly tweaked version of something given to me by a user of this forum. $marketingvalueArray = array('1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5'); $marketingvalueOutput = ""; foreach($marketingvalueArray AS $key => $value) { //### Checks to see if 'outsource' is posted AND whether its an array AND it the value exists i n the posted array $checked = (isset($_POST['marketingvalue']) && is_array($_POST['marketingvalue']) && in_array($key, $_POST['marketingvalue'])) ? 'checked' : '' ; $marketingvalueOutput .= '<input type="radio" class="radio" name="marketingvalue[' . $key .']" value="'. $key .'" '. $checked .'>'. $value .' '; } Also: if (isset($_POST['marketingvalue'])) { $test = ($_POST['marketingvalue']); } Line 164 is where I have referenced $test. I was testing to see what data was coming back through $_POST['marketingvalue']. All I want to do is get a string from radio buttons/checkboxes, rather than an array, so that I can easily export the information into SQL. However, I don't want to totally get rid of the for loop as it has saved me a lot of time, rather than having to input the code for individual radio buttons. I've posted a few other threads about related issues (I've been struggling with this code for the past few days) but no one has been able to help. If someone could point me in the right direction I'd appreciate it greatly. Thanks
  9. I don't think that's the problem. Everything in the page, including the arrays works, even with my use of "custexp[]". I just haven't managed to put together a code which saves the array to the session and my head is spinning from having tried multiple results, to no avail. You said earlier to "save that array to the session then use it when needed" but I don't know how to do that. Bear in mind that if I put the arrays inside if($_SERVER['REQUEST_METHOD'] == 'POST') then the form elements don't display properly, so I had to move the arrays outside of that so I imagine my code needs to look something like this. $custexp2Array = array('1' => 'We are constantly looking to find new ways to improve the overall customer experience.', '2' => 'There is a team in the business specialising in managing the customer experience.', '3' => 'There is a dedicated position within the business for customer experience management.', '4' => 'Customer experience management is something that receives great consideration at a board/strategic level.'); $custexp2Output = ''; foreach($custexp2Array AS $key => $value) { $checked = (isset($_POST['custexp']) && is_array($_POST['custexp']) && in_array($key, $_POST['custexp'])) ? 'checked' : '' ; $custexp2Output .= '<input type="checkbox" class="checkbox" name="custexp[]" value="'. $key .'" '. $checked .'>'. $value .'<br />'; if($_SERVER['REQUEST_METHOD'] == 'POST') { //PUT CODE HERE TO SAVE TO SESSION } } I've commented the section where I think I need to add code.
  10. Hi Paul, Yes, it's related. I adapted the code you wrote for a second set of checkboxes on the same form page $custexp2Array = array('1' => 'We are constantly looking to find new ways to improve the overall customer experience.', '2' => 'There is a team in the business specialising in managing the customer experience.', '3' => 'There is a dedicated position within the business for customer experience management.', '4' => 'Customer experience management is something that receives great consideration at a board/strategic level.'); $custexp2Output = ''; foreach($custexp2Array AS $key => $value) { $checked = (isset($_POST['custexp']) && is_array($_POST['custexp']) && in_array($key, $_POST['custexp'])) ? 'checked' : '' ; $custexp2Output .= '<input type="checkbox" class="checkbox" name="custexp[]" value="'. $key .'" '. $checked .'>'. $value .'<br />'; } I don't know much about arrays or print_r() so I'm quite confused about how I would use the code you've provided and turn that into session data. I think I've spent too many days working on this survey as my head is literally spinning. Haha.
  11. Hi there, For those who have been following my recent posts, I'm building a web survey and I've hit quite a few road blocks. I've almost completed the project now, so hopefully this is my last query! I'm having trouble creating session data based on checkbox selections. The code I've just knocked together isn't working at all. In fact, I created the $custresult variable to test if it was working, but it keeps on coming up as an undefined variable. Bear in mind that "custexp" is a checkbox and, as a result, the user may be selecting multiple options, hence why I've created a different if statement for each option. if (isset($_POST['custexp'])) { if($_POST['custexp'] == "1") { $custexp1 = "Yes"; $_SESSION['custexp1'] = $custexp1; } if($_POST['custexp'] == "2") { $custexp2 = "Yes"; $_SESSION['custexp2'] = $custexp2; } if($_POST['custexp'] == "3") { $custexp3 = "Yes"; $_SESSION['custexp3'] = $custexp3; } if($_POST['custexp'] == "4") { $custexp4 = "Yes"; $_SESSION['custexp4'] = $custexp4; } $custresult = "" . $custexp1 . "" . $custexp2 . "" . $custexp3 . "" . $custexp4 . ""; } Thanks
  12. Actually ignore my last post. That was a stupid question. Haha. I've just tested it and $key, $checked and $value can be used over and over again. Now that I've got the checkboxes working properly, I have one more question... how would I go about storing the values from the checkboxes into a variable so I could save it to the session? And would I need to use separate variables for each checkbox option and indicate Boolean true or false whether selected or not? Thanks
  13. Thank you, that does seem more efficient. Can't believe how much unnecessary code I seem to have wrote. Haha. I'm not too familiar with arrays so just to double-check, would I need to rename $key, $checked or $value to say $key2, $checked2 and $value2 if I were to use this code again for a different set of radio buttons/checkboxes on the same page?
  14. Hi there all, Two questions. Firstly, about keeping radio buttons selected after POST. Managed to get this working on one of my survey pages, but can't seem to get it working on the latest page I'm putting together. I've probably made a minor error but can't seem to work it out. Here's my code. 1 <input type=\"radio\" class=\"radio\" name=\"custexpvalue\" value=\"1\" " . (isset($_POST['custexpvalue']) && $_POST['custexpvalue'] == "1" ? "selected=\"selected\"" : "") ."> 2 <input type=\"radio\" class=\"radio\" name=\"custexpvalue\" value=\"2\" " . (isset($_POST['custexpvalue']) && $_POST['custexpvalue'] == "2" ? "selected=\"selected\"" : "") ."> 3 <input type=\"radio\" class=\"radio\" name=\"custexpvalue\" value=\"3\" " . (isset($_POST['custexpvalue']) && $_POST['custexpvalue'] == "3" ? "selected=\"selected\"" : "") ."> 4 <input type=\"radio\" class=\"radio\" name=\"custexpvalue\" value=\"4\" " . (isset($_POST['custexpvalue']) && $_POST['custexpvalue'] == "4" ? "selected=\"selected\"" : "") ."> 5 <input type=\"radio\" class=\"radio\" name=\"custexpvalue\" value=\"5\" " . (isset($_POST['custexpvalue']) && $_POST['custexpvalue'] == "5" ? "selected=\"selected\"" : "") .">" Secondly, I'm trying to get PHP to store the values of checkboxes when the submit button is hit but because multiple values can be selected I'm not sure how to do this with POST. Here's my code so far: <input type=\"checkbox\" class=\"checkbox\" name=\"outsource\" value=\"1\">Marketing agency<br /> <input type=\"checkbox\" class=\"checkbox\" name=\"outsource\" value=\"2\">PR agency<br /> <input type=\"checkbox\" class=\"checkbox\" name=\"outsource\" value=\"3\">Design studio<br /> <input type=\"checkbox\" class=\"checkbox\" name=\"outsource\" value=\"4\">Marketing consultant<br /> <input type=\"checkbox\" class=\"checkbox\" name=\"outsource\" value=\"5\">Media agency<br /> <input type=\"checkbox\" class=\"checkbox\" name=\"outsource\" value=\"6\">Advertising agency<br /> <input type=\"checkbox\" class=\"checkbox\" name=\"outsource\" value=\"7\">Service or product design agency<br /> <input type=\"checkbox\" class=\"checkbox\" name=\"outsource\" value=\"8\">Customer experience agency<br /> if (isset($_POST['outsource'])) { } Any help would be appreciated.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.