Christopher Bergin Posted August 22, 2012 Share Posted August 22, 2012 In this lesson, Larry uses an elegant solution to populate the scrubbed array: $scrubbed= array_map ('spam_scrubber', $_POST); I thought I'd try a more traditional route just to see if I could and I'm having difficulty. Can anyone correct this logic for me? if ($_SERVER['REQUEST_METHOD'] == 'POST') //$scrubbed= array_map ('spam_scrubber', $_POST); {$scrubbed= array(); foreach ($_POST as $v) $scrubbed= spam_scrubber($v); if (!empty($scrubbed['name']) && !empty($scrubbed['email']) && !empty($scrubbed['comments'])) {$body= "Name: {$scrubbed['name']}\n\nComments:{$scrubbed['comments']}"; $body= wordwrap($body, 70); mail('postoffice@cjbergin.com', 'Contact Form Submission', $body); print "<p><em>Thank-you for contacting me. </em></p>"; $_POST= array();} else print "<p><b>Please fill out the form completely!</b></p>";} all the other sections of the script work according to plan. The output I'm receiving is just one character per field: Name: s Comments:s Link to comment Share on other sites More sharing options...
Larry Posted August 24, 2012 Share Posted August 24, 2012 The problem is you're assigning each spam_scrubber() output to the same variable. Also, you've got some very messed up curly brackets there. Link to comment Share on other sites More sharing options...
Christopher Bergin Posted August 24, 2012 Author Share Posted August 24, 2012 the bracket thing is non-conventional. I find code easier to focus on when it is condensed and composed more like a written language. Anyway, thanks for the response. I changed my loop to read... foreach ($_POST as $k => $v) $scrubbed[$k]= spam_scrubber($v); and it worked. Link to comment Share on other sites More sharing options...
Recommended Posts