473,395 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Omitting form fields if empty

I have a form I'm putting together. The processing will be on a PHP
script that will take all the field names and print them out on the
email it sends to me. No problem there. But what I'd like to do is have
it exclude printing the field name and value when there are any blank
values in the field.

The processing part of the script is this:

if (is_array($val)) {
for ($z=0;$z<count($val);$z++) {
$content .= "$key: $val[$z]\n";
}
} else {
$content .= "$key: $val\n";
}
How would I adapt this to not print a field name with a blank value?

Thanks.

Jul 16 '05 #1
1 4020

"JDJones" <se******@sprynet.com> wrote in message
news:YW07b.290954$Oz4.79719@rwcrnsc54...
I have a form I'm putting together. The processing will be on a PHP
script that will take all the field names and print them out on the
email it sends to me. No problem there. But what I'd like to do is have
it exclude printing the field name and value when there are any blank
values in the field.

The processing part of the script is this:

if (is_array($val)) {
for ($z=0;$z<count($val);$z++) {
$content .= "$key: $val[$z]\n";
}
} else {
$content .= "$key: $val\n";
}
How would I adapt this to not print a field name with a blank value?

Thanks.

if (is_array($val)) {
for ($z=0;$z<count($val);$z++) {

if(strlen($val[$z])>0) // If the length of your value is greater than
zero, then include it
{ $content .= "$key: $val[$z]\n"; }

}
} else {
$content .= "$key: $val\n";
}
Jul 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jason | last post by:
My server does support php, but I cannot get contact form to work. Could use some help to see if any error in php code and appreciate help in advance! Jason <!DOCTYPE html PUBLIC "-//W3C//DTD...
2
by: JDJones | last post by:
I have a form processing script that takes my form info and emails to me. Pretty basic and it works. But I'd like to be able to have it not print a form variable if the value is empty. I know about...
4
by: Gleep | last post by:
Hi PHP coders, I've got an issue I'm stuck with. Imagine there is a large form that has 5 columns and 20 rows. In each row there is a check box - then 4 input fields. I already have the code...
18
by: Stephanie | last post by:
I tried to create an email/contact form but i'am stuck. (i'am a php-newbie) Let me explain (sorry for my bad english, it's not my native language) I have a form with the required fields and the...
11
by: Jim | last post by:
Hi, I keep getting form results emailed to me that would indicate a form from my web site is getting submitted with all fields blank or empty, but my code should preventing users from proceeding...
3
by: Mark R | last post by:
I have one .asp page with a SELECT pulldown list on it and some INPUT fields. When SUBMIT is clicked the form data is submitted to that same page and validated. If INPUT fields are empty the asp...
1
by: Techy | last post by:
I have two fields in my form so called : invoice and cash Now I want to validate this form on the client side with the help of javascript in such a way that if one of these fields is empy an...
7
by: h7qvnk7q001 | last post by:
I'm trying to implement a simple server-side form validation (No Javascript). If the user submits a form with errors, I want to redisplay the same form with the errors highlighted. Once the form...
1
by: G04 | last post by:
Hi All, I have a continuous form with all records. For each field there is a combo in the form header and the form also contains a Toggle button "Apply Filter". When clicked, it changes to...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.