473,513 Members | 2,375 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Excluding form fields if values are empty

4 New Member
I have created a form that I email the submitted results to an email address. The form has several optional fields that I would like to exclude from the sent email if they are empty. Below is the PHP code that I am using now.

foreach ($_POST as $field=>$value)
$message .= "$field: $value\n";
mail($to, $subject, $message);
Apr 3 '08 #1
3 1759
Markus
6,050 Recognized Expert Expert
Try this:
[php]
if(!strlen(trim($_value)) < 1)
{
# do mail
}
[/php]
Regards :)
Apr 3 '08 #2
KHurst
4 New Member
Just to help the next person. This is the code that worked for me. Thanks!


foreach ($_POST as $field=>$value)
if(!strlen(trim($vlaue)) < 1) {
$message .= "$field: $value\n";
}
mail($to, $subject, $message);
Apr 3 '08 #3
Markus
6,050 Recognized Expert Expert
Just to help the next person. This is the code that worked for me. Thanks!


foreach ($_POST as $field=>$value)
if(!strlen(trim($vlaue)) < 1) {
$message .= "$field: $value\n";
}
mail($to, $subject, $message);
Sweet!

Remember to use code tags when posting code, though.

See you around dude!
Apr 3 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2091
by: Glyphman | last post by:
I have a bunch of pages with long forms, with lots of input types-text, radios, textareas, and the debugging process has become overwhelming. What I need to happen is to make sure that 1. Every...
11
8724
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
4186
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...
4
1826
by: kimimaro | last post by:
Thank you for your help I think I know what the problem is. Firstly the add_record cannot read the record.txt or something if the record.txt (in which I used it to store the details of each record)...
7
1241
by: cFleury | last post by:
I have an ASP.NET web form that is retaining values over different stations on the network, how can I stop this behavior ?. I didn’t do anything special to cause it. Thanks C.Fleury
5
5790
by: AP | last post by:
Hello Any suggestions on the most efficient way to generate a random number from a range that will not return values specified in an array?
4
3179
by: Rolf Rosenquist | last post by:
From a page with a form I collect the fields in the next page. The fields are compared with a database and if a certain condition does not fit, I want to go back to the first page with the form,...
18
5772
by: Axel Dahmen | last post by:
Hi, trying to submit an ASPX form using the key (using IE6) the page is not submitted in my web project. Trying to debug the pages' JavaScript code I noticed that there's some ASP.NET client...
4
4812
by: Fred!head | last post by:
Hi, Probably this is a newbie question so I appreciate you bearing with me. I've got an application where users can create forms with name= values they define. I'd like to write a script that...
0
7391
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7553
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
7542
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...
0
5697
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3247
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3235
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1609
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.