SHARE
Facebook X Pinterest WhatsApp

Order Form Part 10: The PHP Script – Confirmations

Written By
thumbnail
Vince Barnes
Vince Barnes
Aug 11, 2005

Now that our script has verified that we have good data, we need to round out
our compliment of data elements.  It would be possible to retrieve all
these elements from the form, relying on the JavaScript calculations for the
amounts.  That would be a reasonable idea, since it would mean that the
calculations are only performed in one place and would be easier to maintain,
but, for the sake of illustration once again, we are going to calculate the
amount fields in our server-side PHP script.

Here’s the code we need:

 

//we do not need the rest of the form fields as we can just calculate them


from the whole numbers


if( !empty($_POST

[

"

qtyA

"

]

) )


{


   

$qtyA = $_POST

[

"

qtyA

"

]

;


   

$totalA = $qtyA * 1.25;


}


else


{


   

$qtyA = 0;


   

$totalA = 0;


}

 

if( !empty($_POST

[

"

qtyB

"

]

) )


{


   

$qtyB = $_POST

[

"

qtyB

"

]

;


   

$totalB = $qtyB * 2.35;


}


else


{


   

$qtyB = 0;


   

$totalB = 0;


}

 

if( !empty($_POST

[

"

qtyC

"

]

) )


{


   

$qtyC = $_POST

[

"

qtyC

"

]

;


   

$totalC = $qtyC * 3.45;


}


else


{


   

$qtyC = 0;


   

$totalC = 0;


}

 

$GrandTotal = $totalA + $totalB + $totalC;

 

Nothing too complicated about that!

OK!  Now that we have all our data elements we can send out our
confirmation email, and another to our own "Order Processing Department" to
let them (our self, perhaps?!!) know that an order has been entered. 
One thing to remember when sending out these confirmation emails, though it
doesn’t apply to our present example, is that it is unwise (or worse) to
include any credit card information in an email.  It’s always worth
paying attention to the kind of information you do send via email —
sensitive information is just that, sensitive.

So, to the emails:

 

//we have our data, and now build up an email message to send


$mailto =

"

orders@ourdomain.com

"

;


$subject =

"

Web Order

"

;

 

$body

 

=

"

The following confirms the details of your order:n

"

;


$body .=

"

nn

"

;


$body .=

"

Name:

"

. $Name .

"

n

"

;


$body .=

"

Email:

"

. $Email .

"

n

"

;


$body .=

"

Other Contact Info:

"

. $OtherInfo .

"

n

"

;


$body .=

"

nn

"

;


$body .=

"

Class A Widgets: (

"

. $qtyA .

"

* 1.25) =

"

. $totalA .

"

n

"

;


$body .=

"

Class B Widgets: (

"

. $qtyB .

"

* 2.35) =

"

. $totalB .

"

n

"

;


$body .=

"

Class C Widgets: (

"

. $qtyC .

"

* 3.45) =

"

. $totalC .

"

n

"

;


$body .=

"

n

"

;


$body .=

"

TOTALS:

"

. $GrandTotal .

"

n

"

;

 

mail($mailto, $subject, $body);


mail($Email, $subject, $body);

Note that when building the body of the email, the first line uses the
assignment operator = while the remaining use the concatenate assignment
operator .=   I thought it worth a mention because it’s easy to miss
the period.

If you wanted to have a different lead line for your order department than
for the customer’s confirmation email, you could build a second body and send
that one to your order desk.  PHP makes life very easy, all things
considered!  There are, of course, lots of other ways you could accomplish
this, but, we only really need one, don’t we?!!

We can also use the body of our email to return a confirmation page to the
browser of our site visitor / customer, like this:

 

//we should state the order was sent


echo

"

The following information was sent.

"

;


echo

"

<

br

>

n

"

;


echo

"

<

pre

>

n

"

;


echo $body;


echo

"

<

/pre

>

n

"

;

PHP is so elegant, don’t you think?  We’re almost
done with processing our form

 

 

 


Return to the previous step  | 
Proceed to the next step

Recommended for you...

Shopify Alternatives
Helpful Tips for Designing a Landing Page that Converts
Five Essential HTML5 Editors
Best Web Hosting Providers
Enrique Corrales
May 31, 2022
HTML Goodies Logo

The original home of HTML tutorials. HTMLGoodies is a website dedicated to publishing tutorials that cover every aspect of being a web developer. We cover programming and web development tutorials on languages and technologies such as HTML, JavaScript, and CSS. In addition, our articles cover web frameworks like Angular and React.JS, as well as popular Content Management Systems (CMS) that include WordPress, Drupal, and Joomla. Website development platforms like Shopify, Squarespace, and Wix are also featured. Topics related to solid web design and Internet Marketing also find a home on HTMLGoodies, as we discuss UX/UI Design, Search Engine Optimization (SEO), and web dev best practices.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.