943,733 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 3574
  • PHP RSS
Jan 4th, 2007
0

Don't display an empty form field?

Expand Post »
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:
HTML Syntax (Toggle Plain Text)
  1. <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:

php Syntax (Toggle Plain Text)
  1. $message = "The following was submitted:\n\n";
  2. foreach($fields as $f => $v){
  3. $message .= sprintf("%20s: %s\n",$v,$_REQUEST[$f]);
  4. }

What would I have to do to make this possible?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
mindfrost82 is offline Offline
38 posts
since Dec 2004
Jan 5th, 2007
0

Re: Don't display an empty form field?

So [php]$message = "The following was submitted:\n\n";
foreach($fields as $f => $v)
{
if ($v)
$message .= sprintf("%20s: %s\n",$v,$_REQUEST[$f]);
}[/php]?
Team Colleague
Reputation Points: 53
Solved Threads: 5
PHP/vBulletin Guru
Gary King is offline Offline
360 posts
since Nov 2003
Jan 6th, 2007
0

Re: Don't display an empty form field?

Click to Expand / Collapse  Quote originally posted by Gary King ...
So [php]$message = "The following was submitted:\n\n";
foreach($fields as $f => $v)
{
if ($v)
$message .= sprintf("%20s: %s\n",$v,$_REQUEST[$f]);
}[/php]?
One problem with this solution is that if the value was 0, it would not be displayed either. So you should better use:
php Syntax (Toggle Plain Text)
  1. if ($v!=="")
Reputation Points: 13
Solved Threads: 2
Junior Poster
php_daemon is offline Offline
138 posts
since Aug 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC