By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,040 Members | 1,103 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,040 IT Pros & Developers. It's quick & easy.

Omitting blank fields in formmail results

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.