I'm using a PHP script called rwf_mail.php (http://www.robertswebforge.com/scripts/rwf_mail.shtml).

It creates a form that can be emailed. It consists of the php file and a plain html file to display the form.

So in the HTML page, I have code similar to:

<input size=50 name="NAME"><br>

The PHP script pulls the $fields{"NAME"} and gets the user input from the form on the HTML page.

It then takes all of the fields defined in the PHP script and emails the field name and the form input.

What happens though is if a field is empty, it still emails the field name.

If the input from the form is blank, I don't want it to email the field name either. Basically just email me the field names with their values.

I believe this is the section of code that creates the message to email:

$message = "The following was submitted:\n\n";
 foreach($fields as $f => $v){
	$message .= sprintf("%20s:  %s\n",$v,$_REQUEST[$f]);
 }

What would I have to do to make this possible?

Recommended Answers

All 2 Replies

So

$message = "The following was submitted:\n\n";
foreach($fields as $f => $v)
{
	if ($v)
		$message .= sprintf("%20s:  %s\n",$v,$_REQUEST[$f]);
}

?

So

$message = "The following was submitted:\n\n";
foreach($fields as $f => $v)
{
	if ($v)
		$message .= sprintf("%20s:  %s\n",$v,$_REQUEST[$f]);
}

?

One problem with this solution is that if the value was 0, it would not be displayed either. So you should better use:

if ($v!=="")
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.