473,396 Members | 2,026 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,396 software developers and data experts.

Omitting blank fields in formmail results

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 using
if $($incoming_fields[$i] = "") {
to find the empty value. I'm just not sure about how to tell it to not
print the empty ones in the results. Can anyone help? Thanks.
Below is the current info used to populate the email sent to me:

//GET POST INFO
$incoming_fields = array_keys($_POST);
$incoming_values = array_values($_POST);

// LOAD EMAIL CONTENTS
for ($i = 0; $i < count($incoming_fields); $i++) {
if($incoming_fields[$i] != "rec_mailto") {
if($incoming_fields[$i] != "rec_subject") {
if($incoming_fields[$i] != "rec_thanks") {
if($incoming_fields[$i] != "opt_mailto_cc") {
if($incoming_fields[$i] != "opt_mailto_bcc") {
// ADD FIELD TO OUTGOING MESSAGE
$message .= "$incoming_fields[$i]: $incoming_values[$i]\n";
}}}}}}

Jul 17 '05 #1
2 1573
On Sat, 10 Apr 2004 00:58:14 +0000, JDJones wrote:
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 using
if $($incoming_fields[$i] = "") {
to find the empty value. I'm just not sure about how to tell it to not
print the empty ones in the results. Can anyone help? Thanks.
Below is the current info used to populate the email sent to me:

//GET POST INFO
$incoming_fields = array_keys($_POST);
$incoming_values = array_values($_POST);

// LOAD EMAIL CONTENTS
for ($i = 0; $i < count($incoming_fields); $i++) {
if($incoming_fields[$i] != "rec_mailto") {
if($incoming_fields[$i] != "rec_subject") {
if($incoming_fields[$i] != "rec_thanks") {
if($incoming_fields[$i] != "opt_mailto_cc") {
if($incoming_fields[$i] != "opt_mailto_bcc") {
// ADD FIELD TO OUTGOING MESSAGE
$message .= "$incoming_fields[$i]: $incoming_values[$i]\n";
}}}}}}

Replace your 'ADD FIELD' line above with something like:
if ($incoming_fields[$i] != '')
$message .= "$incoming_fields[$i]: $incoming_fields[$i]\n";

HTH =)

Regards,

Ian

--
Ian.H
digiServ Network
London, UK
http://digiserv.net/

Jul 17 '05 #2
foreach($_POST as $field => $value){

if((!preg_match("/^(rec_(mailto|subject|thanks)|opt_mailto_(bcc|cc)) $/",
$field)) && empty($field) == false){
$message .= "$field: $value\n";
}
}

This should work, smaller code, and faster (I think).

/*\
|*| MJaC - 15, and at School :o
|*| Need help, just ask!! :)
\*/
Jul 17 '05 #3

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

Similar topics

1
by: JDJones | last post by:
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...
3
by: feel_free_to_spam_me | last post by:
Hi. I'm a sorta novice ASP programmer, so I sure could use some help from of you more experienced gurus.... I've written an ASP page that pulls all records from a table. My query is 'SELECT *...
1
by: Andy | last post by:
I have a simple query that basically pulls in an employee's name, and 3 different scores. I am trying to make a report where each employee shows up on a different page, and the 3 scores are shown...
6
by: Andy | last post by:
Hello, I am having many problems with setting up a parameter query that searches by the criteria entered or returns all records if nothing is entered. I have designed an unbound form with 3...
2
by: Rico | last post by:
Hello, I'm using formmail.asp which is an emailing utility. Basically, the user fills out a request page, clicks "Submit" and the page posts to formmail.asp which emails the user information. ...
4
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 and have downloaded the free script formmail.php (version 4.1b). Wondered if anyone had experienced the same problem I'm having. I'm submitting a form to formmail.php, but...
0
by: LizRickaby | last post by:
My client has several Access databased that they wanted converted into MSSQL to be able to access them online (excuse the pun). I added the first Access database, LenderPrograms, as a table in the...
3
by: Geoff Cox | last post by:
Hello, I am using the formmail.cgi script and wonder if it is possible to have the user enter their email address and then have the results sent to this address by formmail.cgi? If yes, how...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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
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
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,...

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.