Don't display an empty form field?

Reply

Join Date: Dec 2004
Posts: 38
Reputation: mindfrost82 is an unknown quantity at this point 
Solved Threads: 0
mindfrost82 mindfrost82 is offline Offline
Light Poster

Don't display an empty form field?

 
0
  #1
Jan 4th, 2007
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:
  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:

  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?
Reply With Quote Quick reply to this message  
Join Date: Nov 2003
Posts: 360
Reputation: Gary King will become famous soon enough Gary King will become famous soon enough 
Solved Threads: 5
Team Colleague
Gary King's Avatar
Gary King Gary King is offline Offline
PHP/vBulletin Guru

Re: Don't display an empty form field?

 
0
  #2
Jan 5th, 2007
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]?
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 138
Reputation: php_daemon is an unknown quantity at this point 
Solved Threads: 2
php_daemon php_daemon is offline Offline
Junior Poster

Re: Don't display an empty form field?

 
0
  #3
Jan 6th, 2007
Originally Posted by Gary King View Post
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:
  1. if ($v!=="")
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC