473,385 Members | 1,806 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,385 software developers and data experts.

How do I exlude an empty field from being submitted?

moishy
104 100+
I get the form emailed to me, but I get the following:

Product_01:
Product_02: 1
Product_03:
Product_04: 4
Product_05:

So is there a way that I'll only see:

Product_02: 1
Product_04: 4

Thanx.
Oct 5 '06 #1
8 2046
ronverdonk
4,258 Expert 4TB
What form? What emailed to me? What is your problem?
If you are double posting this thread will be closed.

Ronald :cool:
Oct 5 '06 #2
moishy
104 100+
What I'm saying is:
I have a form on my website which you fill out your contact info, and your desired quantity of product.

the form is of this type:

Name: _____
Phone: _____
Email: _____

___ Product 1
___ Product 2
___ Product 3

So I've preveously posted a question about not filling out the required fields, which will earn you to be sent to the HTTP_REFFER.

So that's solved.

So if somebody submits a form, neglecting to fill out his name, the page will refresh, and not submit.

But my problem now is:
that when a costomer is buying 1 of Product_2, The email mailed to me upon submit will say:

Name: John Doe
Phone: 1234-567-8910
Email: me@mydomain.com
Product_01:
Product_02: 1
Product_03:

But I wanted to just remain with:

Name: John Doe
Phone: 1234-567-8910
Email: me@mydomain.com
Product_02: 1

So how do I omit an empty field from being included in the email?

Did I clarify myself?
Oct 5 '06 #3
ronverdonk
4,258 Expert 4TB
We can only deduct that from the code that builds and fills the email message with the values. So post that code here and we'll have a look.

Ronald :cool:
Oct 6 '06 #4
vssp
268 100+
Any possibility Are u post the code?
Oct 6 '06 #5
bevort
53
As soon as you press the submit button in a form the complete form is send to the server. thus empty fields are also send and will show up as empty in your email you get from this form.
If you do not want this, send the form to the server (to itself) and check in an IF ($submit) {} each var and make a mail to yourself using
mail ( string to, string subject, string message [, string additional_headers [, string additional_parameters]] )
Read more explanation on this on php.net
Oct 6 '06 #6
moishy
104 100+
Here's the code:

[PHP]<?php

/*
Enter the email address below to send the form to:
*/

$my_email = "me@mydomain.com";


// This line prevents values being entered in a URL

if ($_SERVER['REQUEST_METHOD'] != "POST"){exit;}

// Check referrer is from same site.

if(!(isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER']) && stristr($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST']))){print "Please enable referrer logging to use this contact form. Your message was not sent."; exit;}

// Describe function to check for new lines.

function new_line_check($a)
{

if(preg_match('`[\r\n]`',$a)){header("location: $_SERVER[HTTP_REFERER]");exit;}

}

new_line_check($_POST['Name']);

// Check for disallowed characters in the Name and Email fields.

$disallowed_name = array(':',';','"','=','(',')','{','}','@');

foreach($disallowed_name as $value)
{

if(stristr($_POST['Name'],$value)){header("location: $_SERVER[HTTP_REFERER]");exit;}

}

new_line_check($_POST['Email']);

$disallowed_email = array(':',';',"'",'"','=','(',')','{','}');

foreach($disallowed_email as $value)
{

if(stristr($_POST['Email'],$value)){header("location: $_SERVER[HTTP_REFERER]");exit;}

}

$message = "";



# This Block I added thanks to your help
# Avoid empty message - If empty - Go back

if(empty($_POST['Name'])){header("location: $_SERVER[HTTP_REFERER]");exit;


}else{

}


# I use this Block not to email me the submit button
# Fields to Avoid
$ex=array();
$ex[]="submit,submit2"; # Where submit is the name of the submit button.

# iterate the $_POST array
foreach ($_POST as $key=>$value) {
if (!in_array($key, $ex)) {
$message.=$key.": " . $value . "\n";
}
}

$message = stripslashes($message);

$subject = "e-Form";
$headers = "From: " . $_POST['Email'] . "\n" . "Return-Path: " . $_POST['Email'] . "\n" . "Reply-To: " . $_POST['Email'] . "\n";

mail($my_email,$subject,$message,$headers);



?>
[/PHP]
Oct 6 '06 #7
ronverdonk
4,258 Expert 4TB
Replace the # iterate the $_POST array with:
[php]# iterate the $_POST array
foreach ($_POST as $key=>$value) {
if (!in_array($key, $ex) AND $value > "" AND $value != 0) {
$message.=$key.": " . $value . "\n";
}
} [/php]

Ronald :cool:
Oct 9 '06 #8
moishy
104 100+
Thanks Ronald!
I based my code on what you wrote:
[PHP]# iterate the $_POST array
foreach ($_POST as $key=>$value) {
if (!in_array($key, $ex) AND $value != "") {
$message.=$key.": " . $value . "\n";}
} [/PHP]
Oct 9 '06 #9

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

Similar topics

3
by: lkrubner | last post by:
A friend using my software called me and said some templates were being reset to default when he submitted a form. I'm trying to track down the problem. It looks like when he assigns a template to...
5
by: Adrian Parker | last post by:
Hi. I have a date time picker in my program which uses ADO to read from an Access database. It works perfectly, unless the database is empty (no records) when opened. When you try to open an...
1
by: compusup3000 | last post by:
Hi, I have an orders database and I need to be able to write a query that groups sales by: 1. Date 2. Time of day (both am and pm) I currently have a date/time field named "Submitted" that...
5
by: Thejo | last post by:
Hi all, I started programming in PHP recently and have a query about empty $_POST arrays. I can see two scenarios when this could happen. 1. When some tries to directly load the page to which...
0
by: Shan Plourde | last post by:
Hi everyone, I have been using various regular expressions with the ASP.NET RegularExpressionValidator for quite some time. In general it works very well. One of the common regex's that I use...
1
by: glenn | last post by:
Hi folks, I am using an Access database, VB.NET and ADO.NET working with a DataGrid control. MY datagrid table has both a date_sent and a date_ans field. When I Insert a record in my SQL...
2
by: David - Australia | last post by:
G'day from Australia, I'm hoping some bright spark may be able to help me with this one. I'm sure that it can be done, I've just hit a wall with it. So I'm opening it up. I'm storing student...
26
by: pepper.gabriela | last post by:
Hello, a stupid question but... page_A.php is a page with a form. The user inserts text in four fields, then he clicks a submit button. The data goes to page_B.php: this page controls the data...
3
by: KHurst | last post by:
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...
6
Dormilich
by: Dormilich | last post by:
Hi, I've got a strange behaviour I can't explain. the form is submitted if a) no field is filled, b) only one field is filled. if both fields are filled I get: XML processing error: no...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...

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.