0

Hi there

I'm having a problem with a script.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Language" content="en-gb" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Thank You for your order!</title>
<style type="text/css">
.style1 {
	text-align: center;
}
.style2 {
	font-size: x-large;
	font-family: Arial, Helvetica, sans-serif;
	color: #000080;
}
.style3 {
	text-align: center;
	font-family: Arial, Helvetica, sans-serif;
	color: #000080;
}
</style>
</head>

<body>
<script language="php">
$email = $POST[email];
$mailto = "emailme@youknowwhere.com";
$mailsubj = "Order from xxxx";
$mailhead = "From: xxxx\n";
reset ($HTTP_POST_VARS);
$mailbody = "Order from xxxx:\n";
while (list ($key, $val) = each ($HTTP_POST_VARS)) { $mailbody .= "$key : $val\n"; }
if (!eregi("\n",$HTTP_POST_VARS[email])) { mail($mailto, $mailsubj, $mailbody, $mailhead); }
</script>
<p class="style1"><span class="style2"><strong>Thanks for your order!</strong></span></p>
<p class="style1">&nbsp;</p>
<p class="style3"><strong>Sit back relax and your meal will be with you in 
45-60mins</strong></p>
<p class="style3">&nbsp;</p>
<p class="style3"><strong>Any problems give the store a call: 01772 888 888</strong></p>
</body>

</html>

Basically its going to allow people to order food via my website for a takeaway.

However upon testing the script its sending me the entire list of items with numbers next to the items that have been ordered...everything else on the form is fine, total amount, delivery details etc...thats perfect.

I simply don't want to see my menu being emailed to me everytime someone orders food, plus having the entire menu emailed and having to work out whats been ordered is going to be a nightmare.

Like I said the rest of the form is fine and what we receive on testing.

The online working demo can be found here, http://www.kwipple.com - please feel free to use it etc to get to the thanks.php page where the script is taken from...it comes directly to me.

Your help is much appriciated.


Justin

Edited by nav33n: Changed code snippet to forum thread. Use the snippet textbox to post your working and fully tested code snippet.

4
Contributors
10
Replies
11
Views
7 Years
Discussion Span
Last Post by misterrmac
-1

It will always post what ever is on your form. So you must check whether value>0 then add that item is value is 0 or null then ignore that item.

0

Could you please show / explain please - not very familar with PHP and its workings, I'm surprise I got this far!

This is what comes through on email....

PROD_HeroBurrito_2_99 : 2
PROD_SpeltBread_4_99 : 1
PROD_SPMG_4_99 : 3
PROD_SPCR_4_99 : 4
PROD_SW_3_99 : 5
PROD_SWMG_3_99 : 3
PROD_RY_4_99 : 4
PROD_KT_4_99 :
PROD_KCR_4_50 :
PROD_KA_4_99 :
PROD_AG_2_99 :
TOTAL : 97.78
name : a
address : b
address0 : a
mobile : 3434
email : 334
requests : d
Submit : Deliver my Food!


Which isn't what I want, what I want is this:

PROD_HeroBurrito_2_99 : 2
PROD_SpeltBread_4_99 : 1
PROD_SPMG_4_99 : 3
PROD_SPCR_4_99 : 4
PROD_SW_3_99 : 5
PROD_SWMG_3_99 : 3
PROD_RY_4_99 : 4

TOTAL : 97.78

name : a
address : b
address0 : a
mobile : 3434
email : 334
requests : d
Submit : Deliver my Food!
====================================

Can it be done??

Edited by JSHGROUP: n/a

0

HERES THE CODE:

INDEX.HTM (THANKS.PHP BELOW)

<HTML>
<HEAD>
<TITLE>Order Form Test</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <meta name="description" content="P " />
    <meta name="keywords" content="p " />
    <meta name="owner" content="JSHGROUP, PRESTONTAKEAWAYS" />
    <meta name="copyright" content="PRESTONTAKEAWAYS 2010" />
    <meta name="author" content="PRESTONTAKEAWAYS" />
    <meta name="rating" content="General" />
    <meta name="revisit-after" content="1 days" />
    
<style type="text/css">
.style1 {
	font-size: small;
	font-weight: bold;
}
.style4 {
	font-size: small;
	text-align: right;
}
.style5 {
	font-size: small;
}
.style6 {
	font-size: small;
	text-align: center;
}
.style7 {
	font-size: small;
	font-weight: bold;
	text-align: center;
}
.style8 {
	border-width: 0;
	background-color: #FFFFFF;
}
.style9 {
	font-size: small;
	font-weight: bold;
	text-align: right;
}
.style10 {
	font-size: small;
	font-weight: bold;
	text-align: right;
	color: #000080;
}
.style11 {
	font-size: small;
	text-align: left;
	color: #000080;
}
.style12 {
	font-size: small;
	text-align: right;
	background-color: #CCCCCC;
}
.style14 {
	text-align: left;
}
.style15 {
	font-size: small;
	text-align: left;
}
.style16 {
	font-family: "Times New Roman";
}
.style17 {
	text-align: center;
}
.style18 {
	font-size: small;
	text-align: right;
	color: #000080;
}
</style>

</HEAD>

<LINK REL="stylesheet" TYPE="text/css" HREF="/stylesheet.css">

<script language="JavaScript" type="text/javascript">
<!--

function CalculateTotal(frm) {
    var order_total = 0

    // Run through all the form fields
    for (var i=0; i < frm.elements.length; ++i) {

        // Get the current field
        form_field = frm.elements[i]

        // Get the field's name
        form_name = form_field.name

        // Is it a "product" field?
        if (form_name.substring(0,4) == "PROD") {

            // If so, extract the price from the name
            item_price = parseFloat(form_name.substring(form_name.lastIndexOf("_") + 1))

            // Get the quantity
            item_quantity = parseInt(form_field.value)

            // Update the order total
            if (item_quantity >= 0) {
                order_total += item_quantity * item_price
            }
        }
    }

    // Display the total rounded to two decimal places
    frm.TOTAL.value = round_decimals(order_total, 2)
}

function round_decimals(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
}

function pad_with_zeros(rounded_value, decimal_places) {

    // Convert the number to a string
    var value_string = rounded_value.toString()
    
    // Locate the decimal point
    var decimal_location = value_string.indexOf(".")

    // Is there a decimal point?
    if (decimal_location == -1) {
        
        // If no, then all decimal places will be padded with 0s
        decimal_part_length = 0
        
        // If decimal_places is greater than zero, tack on a decimal point
        value_string += decimal_places > 0 ? "." : ""
    }
    else {

        // If yes, then only the extra decimal places will be padded with 0s
        decimal_part_length = value_string.length - decimal_location - 1
    }
    
    // Calculate the number of decimal places that need to be padded with 0s
    var pad_total = decimal_places - decimal_part_length
    
    if (pad_total > 0) {
        
        // Pad the string with 0s
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0"
        }
    return value_string
}


//-->
</script>

<BODY MARGINWIDTH=0 MARGINHEIGHT=0 LEFTMARGIN=0 TOPMARGIN=0 BGCOLOR=#FFFFFF>


<A NAME="top"></A>

<!--START THE HEADER-->

<!--END THE HEADER-->

<!--START THE CONTENT-->
<DIV STYLE="margin-left: 5px; font-family: Arial, Verdana, Helvetica, Geneva, 'MS Sans Serif'">

<CENTER><TABLE WIDTH=610 CELLSPACING=0 CELLPADDING=0><TR><TD><IMG SRC="/Graphics/spacer.gif" HEIGHT=1 WIDTH=610><BR>

	<form method="POST" action="thanks.php">

<H3>PrestonTakeaways Order Form Test</H3>


<TABLE class="style8">

<TR>

<TD class="style9" style="width: 1049px">Description</TD>
	<TD style="width: 224px" class="style7">Price (each)</TD><TD ALIGN="CENTER" class="style1" style="width: 166px">
QTY:</TD>

</TR>
<TR>
<TD style="width: 1049px" class="style5">&nbsp;</TD>
<TD style="width: 224px" class="style6">&nbsp;</TD>
<TD ALIGN="CENTER" style="width: 166px" class="style5">
&nbsp;</TD>
</TR>
<TR>
<TD style="width: 1049px" class="style15">Hero Burrito</TD>
<TD style="width: 224px" class="style6">£2.99</TD>
<TD ALIGN="CENTER" style="width: 166px" class="style5">
<INPUT TYPE=TEXT NAME="PROD_HeroBurrito_2.99" SIZE=3 MAXLENGTH=3 onChange="CalculateTotal(this.form)"></TD>
</TR>
<TR>
<TD style="width: 1049px" class="style15">&nbsp;</TD>
<TD style="width: 224px" class="style6">&nbsp;</TD>
<TD ALIGN="CENTER" style="width: 166px" class="style5">
&nbsp;</TD>
</TR>
<TR>
<TD style="width: 1049px" class="style15">S</TD>
<TD style="width: 224px" class="style6">£4.99</TD>
<TD ALIGN="CENTER" style="width: 166px" class="style5">
<INPUT TYPE=TEXT NAME="PROD_SpeltBread_4.99" SIZE=3 MAXLENGTH=3 onChange="CalculateTotal(this.form)"></TD>
</TR>
<TR>
	<TD style="width: 1049px" class="style15">S</TD>
	<TD style="width: 224px" class="style6">£4.99</TD>
	<TD ALIGN="CENTER" style="width: 166px" class="style5">
	<INPUT TYPE=TEXT NAME="PROD_SPMG_4.99" SIZE=3 MAXLENGTH=3 onChange="CalculateTotal(this.form)"></TD>
</TR>
<TR>
	<TD style="width: 1049px" class="style15">S</TD>
	<TD style="width: 224px" class="style6">£4.99</TD>

	<TD ALIGN="CENTER" style="width: 166px" class="style5">
	<INPUT TYPE=TEXT NAME="PROD_SPCR_4.99" SIZE=3 MAXLENGTH=3 onChange="CalculateTotal(this.form)"></TD>

</TR>
<TR>
	<TD style="width: 1049px" class="style15">S</TD>
	<TD style="width: 224px" class="style6">£3.99</TD>
	<TD ALIGN="CENTER" style="width: 166px" class="style5">
	<INPUT TYPE=TEXT NAME="PROD_SW_3.99" SIZE=3 MAXLENGTH=3 onChange="CalculateTotal(this.form)"></TD>
</TR>
<TR>
	<TD style="width: 1049px" class="style15">S</TD>
	<TD style="width: 224px" class="style6">£3.99</TD>
	<TD ALIGN="CENTER" style="width: 166px" class="style5">
	<INPUT TYPE=TEXT NAME="PROD_SWMG_3.99" SIZE=3 MAXLENGTH=3 onChange="CalculateTotal(this.form)"></TD>
</TR>
<TR>
	<TD style="width: 1049px" class="style15">R</TD>
	<TD style="width: 224px" class="style6">£4.99</TD>
	<TD ALIGN="CENTER" style="width: 166px" class="style5">
	<INPUT TYPE=TEXT NAME="PROD_RY_4.99" SIZE=3 MAXLENGTH=3 onChange="CalculateTotal(this.form)"></TD>
</TR>
<TR>
	<TD style="width: 1049px" class="style14"><span class="style5">K</span></TD>
	<TD style="width: 224px" class="style6">£4.99</TD>

	<TD ALIGN="CENTER" style="width: 166px" class="style5">
	<INPUT TYPE=TEXT NAME="PROD_KT_4.99" SIZE=3 MAXLENGTH=3 onChange="CalculateTotal(this.form)"></TD>

</TR>
<TR>
	<TD style="width: 1049px" class="style15">K</TD>
	<TD style="width: 224px" class="style6">£4.50</TD>
	<TD ALIGN="CENTER" style="width: 166px" class="style5">
	<INPUT TYPE=TEXT NAME="PROD_KCR_4.50" SIZE=3 MAXLENGTH=3 onChange="CalculateTotal(this.form)"></TD>
</TR>
<TR>
	<TD style="width: 1049px" class="style15">K</TD>
	<TD style="width: 224px" class="style6">£4.99</TD>
	<TD ALIGN="CENTER" style="width: 166px" class="style5">
	<INPUT TYPE=TEXT NAME="PROD_KA_4.99" SIZE=3 MAXLENGTH=3 onChange="CalculateTotal(this.form)"></TD>
</TR>
<TR>
	<TD style="width: 1049px" class="style15">A</TD>
	<TD style="width: 224px" class="style6">£2.99</TD>
	<TD ALIGN="CENTER" style="width: 166px" class="style5">
	<INPUT TYPE=TEXT NAME="PROD_AG_2.99" SIZE=3 MAXLENGTH=3 onChange="CalculateTotal(this.form)"></TD>
	<TR>
	<TD style="width: 1049px" class="style18"><strong><em>ORDER TOTAL</em></strong></TD>
	<TD style="width: 224px" class="style6">£<INPUT TYPE=TEXT NAME=TOTAL SIZE=10 onFocus="this.form.elements[0].focus()"></TD>

		<TD style="width: 166px" class="style5"><BR></TD>
	
	<TR>
	<TD class="style4" colspan="3">&nbsp;</TD>
	<TR>
	<TD class="style12" colspan="3">&nbsp;</TD>
	<TR>
	<TD class="style11" colspan="3"><strong><em>Delivery Details</em></strong></TD>
		
</TABLE>

<P class="style17">

<table style="width: 100%">
	<tr>
		<td style="width: 242px" class="style10"><strong>Name</strong></td>
		<td> <input type="TEXT" name="name" style="width: 275px"></td>
	</tr>
	<tr>
		<td style="width: 242px" class="style10"><strong>Address</strong></td>
		<td> <input name="address" style="width: 275px"></td>
	</tr>
	<tr>
		<td style="width: 242px" class="style10" valign="top"><strong>Postcode 		</strong></td>
		<td> <input name="postcode" style="width: 102px"></td>
	</tr>
	<tr>
		<td style="width: 242px" class="style10">Mobile</td>
		<td> <input name="mobile"></td>
	</tr>
	<tr>
		<td style="width: 242px" class="style10">Email</td>
		<td> <input name="email"></td>
	</tr>
	<tr>
		<td style="width: 242px" class="style10">&nbsp;</td>
		<td>&nbsp;</td>
	</tr>
	<tr>
		<td style="width: 242px" class="style10" valign="top">Any requests that 
		the <br>
		kitchen should know about?</td>
		<td><textarea name="requests" style="width: 275px; height: 70px;"></textarea>&nbsp;</td>
	</tr>
	<tr>
		<td style="width: 242px" class="style9">&nbsp;</td>
		<td>&nbsp;</td>
	</tr>
</table>
<br />
<input type="submit" name="Submit" value="Deliver my Food!" style="height: 24px" />
<input name="Reset1" type="reset" value="clear order" style="height: 24px" /></form>


</FORM>


 

</TD></TR></TABLE>
<br>
<br>
<span class="style5">[Name] powered by 
<a target="_blank" href="http://www.prestontakeaways.co.uk">PrestonTakeaways.co.uk</a><br>
PrestonTakeaways.co.uk <span class="style16">©</span> 2010</span>
</BODY>
</HTML>

THANKS.PHP

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Language" content="en-gb" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Thank You for your order!</title>
<style type="text/css">
.style1 {
	text-align: center;
}
.style2 {
	font-size: x-large;
	font-family: Arial, Helvetica, sans-serif;
	color: #000080;
}
.style3 {
	text-align: center;
	font-family: Arial, Helvetica, sans-serif;
	color: #000080;
}
</style>
</head>

<body>
<script language="php">
$email = $POST[email];
$mailto = "justin@jshgroup.co.uk";
$mailsubj = "Order from PrestonTakeaways";
$mailhead = "From: Preston Takeaways\n";
reset ($HTTP_POST_VARS);
$mailbody = "Order from PrestonTakeaways:\n";
while (list ($key, $val) = each ($HTTP_POST_VARS)) { $mailbody .= "$key : $val\n"; }
if (!eregi("\n",$HTTP_POST_VARS[email])) { mail($mailto, $mailsubj, $mailbody, $mailhead); }
</script>
<p class="style1"><span class="style2"><strong>Thanks for your order!</strong></span></p>
<p class="style1">&nbsp;</p>
<p class="style3"><strong>Sit back relax and your meal will be with you in 
45-60mins</strong></p>
<p class="style3">&nbsp;</p>
<p class="style3"><strong>Any problems give the store a call: [number]</strong></p>
</body>
</html>

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

0

If I were you I would search for:

while (list ($key, $val) = each ($HTTP_POST_VARS)) { $mailbody .= "$key : $val\n"; }

And define all options seperate, so you can easily order it.

like this:

//Display it:
$mailbody .= "Name: ".$_POST["PROD_HeroBurrito_2.99"]."/n";

Do that for every product/option.
You should change PROD_HeroBurrito_2.99 to the Form name.

I hope you understand what I mean =)

Edited by Viletung: n/a

0

If I were you I would search for:

while (list ($key, $val) = each ($HTTP_POST_VARS)) { $mailbody .= "$key : $val\n"; }

And define all options seperate, so you can easily order it.

like this:

//Display it:
$mailbody .= "Name: ".$_POST["PROD_HeroBurrito_2.99"]."/n";

Do that for every product/option.
You should change PROD_HeroBurrito_2.99 to the Form name.

I hope you understand what I mean =)

Hi Viletung

Do I need to remove this:

while (list ($key, $val) = each ($HTTP_POST_VARS)) { $mailbody .= "$key : $val\n"; }

Completly and replace it with;

$mailbody .= "Name: ".$_POST["PROD_HeroBurrito_2.99"]."/n";


It isnt very clear.

Justin

Edited by JSHGROUP: n/a

-1

Sure,

I meant that you should write each product.

Example

$mailbody .= "Product1: ".$_POST["PROD_HeroBurrito_2.99"]."/n";
$mailbody .= "Product2: .$_POST["PROD_SpeltBread_4.99"]."/n";
$mailbody .= "Product3: ".$_POST["PROD_SPMG_4_99"]."/n";
$mailbody .= "Product4: ".$_POST["PROD_SPCR_4_99"]."/n";

I'm not sure if you know what the $_POST function does, if yes, then you can see that what is between: $_POST[" and "] is the same as the name tag in your form. Of course you need to add more products. I hope you understand what I mean, if not I would like to explain better, but I don't know a better way to explain at the moment.

0
<body>
<script language="php">
$email = $POST[email];
$mailto = "justin@jshgroup.co.uk";
$mailsubj = "Order from PrestonTakeaways";
$mailhead = "From: Preston Takeaways\n";
reset ($HTTP_POST_VARS);
$mailbody = "Order from PrestonTakeaways:\n";
while (list ($key, $val) = each ($HTTP_POST_VARS)) { $mailbody .= "Name: ".$_POST["PROD_HeroBurrito_2.99"]."/n"; }
if (!eregi("\n",$HTTP_POST_VARS[email])) { mail($mailto, $mailsubj, $mailbody, $mailhead); }
</script>
<p class="style1"><span class="style2"><strong>Thanks for your order!</strong></span></p>
<p class="style1">&nbsp;</p>
<p class="style3"><strong>Sit back relax and your meal will be with you in 
45-60mins</strong></p>
<p class="style3">&nbsp;</p>
<p class="style3"><strong>Any problems give the store a call: [number]</strong></p>
</body>
</html>

Where on the above code does this which you have provided go?

#
$mailbody .= "Product1: ".$_POST["PROD_HeroBurrito_2.99"]."/n";
#
$mailbody .= "Product2: .$_POST["PROD_SpeltBread_4.99"]."/n";
#
$mailbody .= "Product3: ".$_POST["PROD_SPMG_4_99"]."/n";
#
$mailbody .= "Product4: ".$_POST["PROD_SPCR_4_99"]."/n";


Many thanks, Justin

0

What you've given me doesn't do what I want it to do. Its still sending through everything that is listed on the form. It does that anyway without any new code being added.

Its quite simple what I want...

When a customer enters a figure next to a product on the form, as long as its 1 or greater it should be detected by the script to add that product to the email body along with all the other information, such as total price and delivery details. I do NOT want it sending fields with "0" or a blank qty box to the email address as this is pointless.

Edited by JSHGROUP: n/a

0

Try this:
Change this:

while (list ($key, $val) = each ($HTTP_POST_VARS)) { $mailbody .= "$key : $val\n"; }

to this

while (list ($key, $val) = each ($HTTP_POST_VARS)) { 
    If($val != '') {
        $mailbody .= "$key : $val\n";
    }
}

That if($val != '') is checking to see that the value in the field is not blank. If its not, it gets added to the email. Otherwise it gets skipped.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.