PDA

View Full Version : Saving POST entries to variables


pb&j
01-18-2003, 04:16 PM
Simple question...

Currently I have this...

$webpage = $_POST['webpage'];
$name=$_POST['name'];
$comments=$_POST['comments'];
And so forth...


I'd like to create a loop to automatically put the POST variable into it's own same named variable instead of writing out a ton of lines like above.

While I'm asking... afterwards (not during the previous loop) I'd like a loop to echo the results out. If the result is null, then don't display that line.

::edit::
For those helping, please refer to my second post below for a more updated idea of what I am trying to do. Thanks.
::/edit::


TIA.

Dylan Leblanc
01-18-2003, 05:05 PM
$mypost = $_POST

foreach ($mypost as $value)
echo"{$value}<br>";



Might display a blank line if NULL though...

pb&j
01-18-2003, 05:47 PM
Thanks Dylan.

I tried the foreach thing and it didn't want to work when I adjusted it for a null value. In the meantime, I found this works for me...


$message = "The following information has been sent.\n\n";
if ($HTTP_POST_VARS){
while (list($lvar,$lvalue) = each($HTTP_POST_VARS)){
if (!empty($lvalue)) {$message .= "$lvar\n$lvalue\n\n";}
}
}


All that looks a bit on the "messy" side though. So if anyone has a "cleaner" solution to the above, that would be great.

Basically, it is taking the entered form information, putting it onto one variable $message if it is not empty, and then it is sent out by email.

Cheers :thumbsup: