phpretard Posted February 9, 2008 Share Posted February 9, 2008 Is there a way to capture all of the posted fields in a form with one string?. This as opposed to typing -- $_POST['bunches'] -- many many times? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 9, 2008 Share Posted February 9, 2008 You could do <?php $fields = implode('~',$_POST); ?> which would put all responses into the string $fields separated by the "~" character, but you would loose the field names. If you tell us what you are trying to do, we might be able to help you. Ken Quote Link to comment Share on other sites More sharing options...
phpretard Posted February 9, 2008 Author Share Posted February 9, 2008 I am simple trying to submit a form and email the information from it. I can do that no sweat. I just know there must be a better way then to type $_post['info'] for every field. I have about 40 fields. This isn't detramental, I just would like to know if there is a better way. Thanks a million! -Anthony Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 9, 2008 Share Posted February 9, 2008 The easiest way to get information into an email message is: <?php $to = 'your.email.address@here.com'; $subject = 'Form filled in'; $headers = 'From: your.email@address.here'; $body = print_r($_POST,true); mail($to, $subject, $body, $headers); ?> Ken Quote Link to comment Share on other sites More sharing options...
phpretard Posted February 10, 2008 Author Share Posted February 10, 2008 That worked great. Any pointers on how to manipulate this " [c1name] => Anthony Jones " c1name should be "Customer 1 Name = Anthony Jones". Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 10, 2008 Share Posted February 10, 2008 What the print_r() gives you is the raw information that comes from your form. The string between the "[]" is the name you've put in the "<input>" line of the form. If you want to make it more meaningful you will have to do some more work. Create an array with the correspondence between the field names and what you want. Something like: <?php $flds = array('fld1' => 'field one','c1name'=>'Customer 1 Name','fld3'=>'Field Three'); $bdy = array(); foreach ($flds as $nam => $val) $bdy[] = $val . ' = ' . $_POST[$fld]; $body = implode("\n",$bdy); $to = 'your.email.address@here.com'; $subject = 'Form filled in'; $headers = 'From: your.email@address.here'; mail($to, $subject, $body, $headers); ?> Ken 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.