Page 1 of 1

Forms +mail()

Posted: Mon Jul 04, 2005 6:01 am
by Jim_Bo
Hi,

Basically I have a form with losts of fields and check boxed, but a great number wont have any data input upon submision. When I use mail() to email me a copy of the form as well as the client I only want to email the fields that contained data along with a short description ie

$message = "name: $name";

whats the easyest way to do that?


Cheers

Posted: Mon Jul 04, 2005 6:22 am
by djot
-
Since you want to use php's mail-function, you will have to retrieve all forms data before mailing anyway. So why you can't check whether they are holding data?

djot
-

Posted: Mon Jul 04, 2005 6:28 am
by Chris Corbyn
These two functions are used to check if data exists in a variable.
Everything gets sent, it's just that some will be empty.
It's usually a good idea to use these in form validation if you're not using a more in-depth validation method too.

http://www.php.net/empty
http://www.php.net/isset

Posted: Mon Jul 04, 2005 6:41 am
by smo
Try looping through the name and value pairs like this

Code: Select all

foreach($HTTP_POST_VARS as $key=>$value)
{
$msg .= "$key = $value <br>";
}
Then use the mail function to send the data. If you want only entered data to go to the $msg variables ( not empty data ) then

Code: Select all

foreach($HTTP_POST_VARS as $key=>$value)
{
if(strlen($value) > 1){ // only entered datas will be taken
$msg .= "$key = $value <br>";
}
}
d11wtq | Please use

Code: Select all

tags when posting PHP code  [/color]
Then use the mail function to send the data. If you want only entered data to go to the $msg variables ( not empty data ) then

Code: Select all

foreach($HTTP_POST_VARS as $key=>$value)
{
if(strlen($value) > 1){ // only entered datas will be taken
$msg .= "$key = $value <br>";
}
}
d11wtq | Please use

Code: Select all

tags when posting PHP code  [/color]a]806a]
foreach($HTTP_POST_VARS as $key=>$value)
{
$msg .= "$key = $value <br>";
}
Then use the mail function to send the data. If you want only entered data to go to the $msg variables ( not empty data ) then

Code: Select all

foreach($HTTP_POST_VARS as $key=>$value)
{
if(strlen($value) > 1){ // only entered datas will be taken
$msg .= "$key = $value <br>";
}
}
d11wtq | Please use

Code: Select all

tags when posting PHP code  [/color].= "$key = $value <br>";
}
Then use the mail function to send the data. If you want only entered data to go to the $msg variables ( not empty data ) then

Code: Select all

foreach($HTTP_POST_VARS as $key=>$value)
{
if(strlen($value) > 1){ // only entered datas will be taken
$msg .= "$key = $value &amp1]
foreach($HTTP_POST_VARS as $key=>$value)
{
$msg .= "$key = $value <br>";
}
Then use the mail function to send the data. If you want only entered data to go to the $msg variables ( not empty data ) then

Code: Select all

foreach($HTTP_POST_VARS as $key=&gt;$value)
{
if(strlen($value) > 1){ // only entered datas will be taken
$msg .= h the name and value pairs like this

Code: Select all

foreach($HTTP_POST_VARS as $key=>$value)
{
$msg .= "$key = $value <br>";
}
Then use the mail function to send the data. If you want only entered data to go to the $msg variables ( not empty data ) then

Code: Select all

foreach($HTTP_POST_VARS as $key=>$value)
{
if(strlen($value) > 1){ // only entered datas will be taken
$msg .= "$key = $value <br>";
}
}
d11wtq | Please use

Code: Select all

tags when posting PHP code  [/color]18b806a]
foreach($HTTP_POST_VARS as $key=>$value)
{
$msg .= "$key = $value <br>";
}
Then use the mail function to send the data. If you want only entered data to go to the $msg variables ( not empty data ) then

Code: Select all

foreach($HTTP_POST_VARS as $key=&gt;$value)
{
if(strlen($value) &gt; 1){ // only entereairs like this

Code: Select all

foreach($HTTP_POST_VARS as $key=>$value)
{
$msg .= "$key = $value <br>";
}
Then use the mail function to send the data. If you want only entered data to go to the $msg variables ( not empty data ) then

Code: Select all

foreach($HTTP_POST_VARS as $key=>$value)
{
if(strlen($value) > 1){ // only entered datas will be taken
$msg .= "$key = $value <br>";
}
}
d11wtq | Please use

Code: Select all

tags when posting PHP code  [/color]h the name and value pairs like this

Code: Select all

foreach($HTTP_POST_VARS as $key=>$value)
{
$msg .= "$key = $value <br>";
}
Then use the mail function to send the data. If you want only entered data to go to the $msg variables ( not empty data ) then

Code: Select all

foreach($HTTP_POST_VARS as $key=>$value)
{
if(strlen($value) > 1){ // only entered datas will be taken
$msg .= "$key = $value <br>";
}
}
d11wtq | Please use

Code: Select all

tags when posting PHP code  [/color:16on to send the data. If you want only entered data to go to the $msg variables ( not empty data ) then

Code: Select all

foreach($HTTP_POST_VARS as $key=>$value)
{
if(strlen($value) > 1){ // s like this

Code: Select all

foreach($HTTP_POST_VARS as $key=>$value)
{
$msg .= "$key = $value <br>";
}
Then use the mail function to send the data. If you want only entered data to go to the $msg variables ( not empty data ) then

Code: Select all

foreach($HTTP_POST_VARS as $key=>$value)
{
if(strlen($value) > 1){ // only entered datas will be taken
$msg .= "$key = $value <br>";
}
}
POST_VARS as $key=>$value)
{
$msg .= "$key = $value <br>";
}


Then use the mail function to send the data. If you want only entered data to go to the $msg variables ( not empty data ) then

Code: Select all

foreach($HTTP_POST_VARS as $key=>$value)
{
if(strlen($value) > 1){ // only entered datas will be taken
$msg .= "$key = $value <br>";
}
}
d11wtq | te;$key = $value <br>";
}


Then use the mail function to send the data. If you want only entered data to go to the $msg variables ( not empty data ) then

Code: Select all

foreach($HTTP_POST_VARS as $key=>$value)
{
if(strlen($value) > 1){ // only entered datas will be taken
$msg .= "$key = $value <b
foreach($HTTP_POST_VARS as $key=>$value)
{
$msg .= "$key = $value <br>";
}
Then use the mail function to send the data. If you want only entered data to go to the $msg variables ( not empty data ) then

Code: Select all

foreach($HTTP_POST_VARS as $key=>$value)
{
if(strlen($value) > 1){ // only entered datas will be taken
$msg .= "$key = $value <br>";
}
}
d11wtq | Please use

Code: Select all

tags when posting PHP code  [/color]

Posted: Mon Jul 04, 2005 6:43 am
by djot
better use $_POST instead of $HTTP_POST_VARS for newer PHP versions...