Reputation: 19
Sorta new to PHP.
So OK. I made a very large set of fields on two forms for various products. The forms work. The scripting is in PHP and the form is HTML. Sends an email when you fill it out.
However, it sends ALL fields, even the ones left blank, so that the number column for quantity ordered is top to bottom with zeros, ones, twos, threes, etc. Not really an error per se, but the person reading it now has to wade through and look for the quantity of say, five to ten different items, and ignore the products with the zeros next to them.
Believe me, the current return is not even close to as easy to read as the return I made below, but rather cluttered and you COULD miss a product request quite easily, especially if busy with many orders coming in.
I did not program it to return any zeros for blank fields, but I do not even want it to return the name of the products not ordered at all. I just want it to return only the fields filled in-nothing else, but I have no idea how to.
CURRENT OUTPUT
Product #1 1
Product #2 0
Product #3 3
Product #4 0
Product #5 0
Product #6 0
Product #7 0
Product #8 0
Product #9 0
Product #10 1
Product #11 0
Product #12 0
Product #13 2
Product #14 0
Product #15 0
Product #16 0
Product #17 0
Product #18 0
Product #19 0
DESIRED OUTPUT
Product #1 1
Product #3 3
Product #10 1
Product #13 2
Upvotes: 0
Views: 91
Reputation: 28911
I'm guessing that your email is built by looping through the $_POST
array. So something like this should help:
foreach($_POST AS $key => $val) {
if(empty($val)) {
unset($_POST[$key]);
}
}
Now as you build your email, the zero value POST vars are not even there.
Update: Now that I've seen your full code (which apparently is writing to a file, not directly sending an email) you need to change this line (13):
while (list ($key, $val) = each ($query_vars)) {
And add a simple check right after it, so you end up with:
while (list ($key, $val) = each ($query_vars)) {
if(empty($val)) continue; // If we have an empty value, ignore and move on
Give that a try.
Upvotes: 1