Solved

form processing

Posted on 2009-07-15
31
183 Views
Last Modified: 2013-11-05
I have a web form that I'm using to collect the quantity of an item and the user clicks the continue button. Once the user clicks that I go to a 2nd page where the user enters their demographics and pays for the item.

What I'm trying to do is prevent a user from reaching the 2nd page without going through the 1st page. I set a hidden variable in the 1st page, productpage = 1. So when the user reaches the 2nd page, if the productpage variable is not 1 then the user is redirected to the previous page. I do this because if the user reaches the 2nd page with data and they reload the page all of the data is lost from the previous page.

On the 2nd page I have set global variables within the script to test for the page referrer. After the user passes that test they can continue with the form. I post to the page the data from the previous page.

The next goal on the 2nd page is to have the order form post to itself for processing the order form. After the user clicks the submit button I'm hoping to process the form contents by running a payment process and putting the data into a table if it was a success. The results of the payment process will come back as success, refer to thank you page or denial refer to error page.

As you can see in the code below, I'm not quite there. I'm having issues with the page referrer test and the form posting to itself.

Any suggestions? I'm I making this too complex?
first page code

<form action="orderform.php" method="post" name="orderform" >

<h1 class="subpage" style="padding-left: 10px;">Sunshine Candy</h1>

    <br />

    Price: $1.00

    <br />

    Quantity:

    <input type="text" name="txtbxQuantity" id="txtbxQuantity">

    <br />

    Color: 

    <select name="ddlColor" id="ddlColor">

      <option value="Green">Green</option>

      <option value="Blue">Blue</option>

    </select>

    <br />

        <input type="hidden" name="productSKU" value="101candy">

        <input type="hidden" name="productName" value="Sunshine Candy">

        <input type="hidden" name="unitPrice" value="1.00">

        <input type="hidden" name="description" value="Wonderful candy.">

        <input type="hidden" name="productpage"  value="1">

    <input name="btnSubmit" type="submit" id="btnSubmit" value="Continue" onClick="return ValidateForm()">

</form>
 
 

2nd page code

//global variables

$ref = getenv("HTTP_REFERER");

$productpage = $_POST['productpage'];

//ensure that this page is coming from a product page; if not then it is redirected to the referring page

if ($productpage != "1")

{

	//this must take place before any page output to the browser

	header("Location: $ref");

	exit();

}

//global variables

$productName = $_POST['productName'];

$productSKU = $_POST['productSKU'];

$productDescription = $_POST['description'];

$productColor = $_POST['ddlColor'];

$productQuantity = $_POST['txtbxQuantity'];

$productUnitPrice = $_POST['unitPrice'];

$subTotal = ($productUnitPrice * $productQuantity);

$taxAmount = .07;

$Total = ($subTotal * $taxAmount) + $subTotal;
 

//test for postback

if ($_SERVER['REQUEST_METHOD'] == 'POST') //&& $productpage != "1")//this runs even from page1

{   

//print "Product Name: " . $productName;

//print "<br />";

//print "Product SKU: " . $productSKU;

//print "<br />";

//print "Product Description: " . $productDescription;

//print "<br />";

//print "Color: " . $productColor;

//print "<br />";

//print "Quantity: " . $productQuantity;

//print "<br /><br />";

//print "Unit Price: $" . $productUnitPrice;

//print "<br />";

//print "SubTotal: $" . $subTotal;

//print "<br />";

//print "Final Order Total: $" . $Total;

//print "<hr>";

} 

?>

<form id="orderform" name="orderform" action="<?php echo $_Server['PHP_SELF']; ?>" method="post">
 

<table border="0" align="left" cellpadding="2" cellspacing="0">

  <tr>

    <td colspan="2" align="left" class="larger">Order Summary</td>

    </tr>

  <tr>

    <td colspan="2">&nbsp;</td>

    </tr>

  <tr>

    <td width="43%">Name</td>

    <td width="57%"><?php echo $productName; ?></td>

  </tr>

  <tr>

    <td>SKU</td>

    <td><?php echo $productSKU; ?></td>

  </tr>

  <tr>

    <td>Color</td>

    <td><?php echo $productColor; ?></td>

  </tr>

  <tr>

    <td>Quantity</td>

    <td><?php echo $productQuantity; ?></td>

  </tr>

  <tr>

    <td>&nbsp;</td>

    <td>&nbsp;</td>

  </tr>

  <tr>

    <td>Price</td>

    <td>$<?php echo $productUnitPrice; ?></td>

  </tr>

  <tr>

    <td>SubTotal</td>

    <td>$<?php echo $subTotal; ?></td>

  </tr>

  <tr>

    <td>Tax</td>

    <td><?php echo $taxAmount; ?>%</td>

  </tr>

  <tr>

    <td>Order Total</td>

    <td>$<?php echo $Total; ?></td>

  </tr>

  <tr>

    <td colspan="2">&nbsp;</td>

    </tr>

  <tr>

    <td colspan="2">In order to process your order please complete the following.</td>

    </tr>

  <tr>

    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields"> First Name</td>

    <td>

      <input name="txtbxFName" type="text" class="fm2" id="txtbxFName">

    </td>

  </tr>

  <tr>

    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields"> Last Name</td>

    <td><input name="txtbxLName" type="text" class="fm2" id="txtbxLName"></td>

  </tr>

  <tr>

    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields">Phone (xxx) xxx-xxxx</td>

    <td><input name="txtbxPhone" type="text" class="fm2" id="txtbxPhone"></td>

  </tr>

  <tr>

    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields">Email Address</td>

    <td><input name="txtbxEmail" type="text" class="fm2" id="txtbxEmail"></td>

  </tr>

  <tr>

    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields"> Address</td>

    <td><input name="txtbxAddress1" type="text" class="fm2" id="txtbxAddress1"></td>

  </tr>

  <tr>

    <td>Address</td>

    <td><input name="txtbxAddress2" type="text" class="fm2" id="txtbxAddress2"></td>

  </tr>

  <tr>

    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields"> City</td>

    <td><input name="txtbxCity" type="text" class="fm2" id="txtbxCity"></td>

  </tr>

  <tr>

    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields"> State</td>

    <td>

    <select name="ddlState" size="1" class="fm2">

	<option value="AK" selected>AK</option>

	<option value="AL">AL</option>

	<option value="AR">AR</option>

	<option value="AZ">AZ</option>

	<option value="CA">CA</option>

	<option value="CO">CO</option>

	<option value="CT">CT</option>

	<option value="DC">DC</option>

	<option value="DE">DE</option>

	<option value="FL">FL</option>

	<option value="GA">GA</option>

	<option value="HI">HI</option>

	<option value="IA">IA</option>

	<option value="ID">ID</option>

	<option value="IL">IL</option>

	<option value="IN">IN</option>

	<option value="KS">KS</option>

	<option value="KY">KY</option>

	<option value="LA">LA</option>

	<option value="MA">MA</option>

	<option value="MD">MD</option>

	<option value="ME">ME</option>

	<option value="MI">MI</option>

	<option value="MN">MN</option>

	<option value="MO">MO</option>

	<option value="MS">MS</option>

	<option value="MT">MT</option>

	<option value="NC">NC</option>

	<option value="ND">ND</option>

	<option value="NE">NE</option>

	<option value="NH">NH</option>

	<option value="NJ">NJ</option>

	<option value="NM">NM</option>

	<option value="NV">NV</option>

	<option value="NY">NY</option>

	<option value="OH">OH</option>

	<option value="OK">OK</option>

	<option value="OR">OR</option>

	<option value="PA">PA</option>

	<option value="RI">RI</option>

	<option value="SC">SC</option>

	<option value="SD">SD</option>

	<option value="TN">TN</option>

	<option value="TX">TX</option>

	<option value="UT">UT</option>

	<option value="VA">VA</option>

	<option value="VT">VT</option>

	<option value="WA">WA</option>

	<option value="WI">WI</option>

	<option value="WV">WV</option>

	<option value="WY">WY</option>

</select>

    </td>

  </tr>

  <tr>

    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields"> Zip</td>

    <td><input name="txtbxZip" type="text" class="fm2" id="txtbxZip" maxlength="5"></td>

  </tr>

  <tr>

    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields"> Credit Card Type</td>

    <td>

    <select name="ddlCCType" class="fm2" id="ddlCCType" >

                <option value="001" selected>Visa</option>

                <option value="002">MasterCard</option>

                <option value="003">American Express</option>

                <option value="004">Discover</option>

                </select>

    </td>

  </tr>

  <tr>

    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields"> Credit Card No.</td>

    <td><input name="txtbxCCNum" type="text" class="fm2" id="txtbxCCNum" maxlength="20"></td>

  </tr>

  <tr>

    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields"> CCV No.</td>

    <td><input name="txtbxCCVNum" type="text" class="fm2" id="txtbxCCVNum" size="5" maxlength="4"></td>

  </tr>

  <tr>

    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields"> CC Expiration Date</td>

    <td>

    <SELECT NAME="ddlCCExpireDate" class="fm2">

      <option value="01">01

      <option value="02">02

      <option value="03">03

      <option value="04">04

      <option value="05">05

      <option value="06">06

      <option value="07">07

      <option value="08">08

      <option value="09">09

      <option value="10">10

      <option value="11">11

      <option value="12">12

      </SELECT> 

&nbsp;&nbsp;

    <select name="ddlCCExpireYear" size="1" class="fm2">

                  <option value="2009">2009</option>

                  <option value="2010">2010</option>

                  <option value="2011">2011</option>

                  <option value="2012">2012</option>

                  <option value="2013">2013</option>

                  <option value="2014">2014</option>

                  <option value="2015">2015</option>

                  <option value="2016">2016</option>

                  <option value="2017">2017</option>

                  <option value="2018">2018</option></select>

                  </td>

  </tr>

  <tr>

    <td colspan="2">&nbsp;</td>

    </tr>

  <tr>

    <td colspan="2">

    <input name="btnSubmit" type="submit" class="fmsend" id="btnSubmit" value="Order Now" onClick="return ValidateForm()">

    </td>

    </tr>

  <tr>

    <td colspan="2">&nbsp;</td>

  </tr>

  </table>

</form>

Open in new window

0
Comment
Question by:fwstealer
  • 15
  • 15
31 Comments
 
LVL 14

Expert Comment

by:profya
ID: 24858660
Ok. I haved tested this:
//First page, I named previouspage.php

<form action="orderform.php" method="post" name="orderform" >

<h1 class="subpage" style="padding-left: 10px;">Sunshine Candy</h1>

    <br />

    Price: $1.00

    <br />

    Quantity:

    <input type="text" name="txtbxQuantity" id="txtbxQuantity">

    <br />

    Color:

    <select name="ddlColor" id="ddlColor">

      <option value="Green">Green</option>

      <option value="Blue">Blue</option>

    </select>

    <br />

        <input type="hidden" name="productSKU" value="101candy">

        <input type="hidden" name="productName" value="Sunshine Candy">

        <input type="hidden" name="unitPrice" value="1.00">

        <input type="hidden" name="description" value="Wonderful candy.">

        <input type="hidden" name="productpage"  value="1">

    <input name="btnSubmit" type="submit" id="btnSubmit" value="Continue" onClick="return ValidateForm()">

</form>
 
 
 

//Order page

<?php

if (!isset($_POST['placeOrder']))

{

	$productpage = @$_POST['productpage'];

	//ensure that this page is coming from a product page; if not then it is redirected to the referring page

	if ($productpage != "1")

	{

		//this must take place before any page output to the browser

		header("Location: previouspage.php");

		exit();

	}
 

}

else if ($_POST['placeOrder']==1)//Process order

{

	//global variables

	/*

	$productName = $_POST['productName'];

	$productSKU = $_POST['productSKU'];

	$productDescription = $_POST['description'];

	$productColor = $_POST['ddlColor'];

	$productQuantity = $_POST['txtbxQuantity'];

	$productUnitPrice = $_POST['unitPrice'];

	$subTotal = ($productUnitPrice * $productQuantity);

	$taxAmount = .07;

	$Total = ($subTotal * $taxAmount) + $subTotal;

	*/

}

?>

<form id="orderform" name="orderform" action="<?php echo $_Server['PHP_SELF']; ?>" method="post">
 

<table border="0" align="left" cellpadding="2" cellspacing="0">

  <tr>

    <td colspan="2" align="left" class="larger">Order Summary</td>

    </tr>

  <tr>

    <td colspan="2">&nbsp;</td>

    </tr>

  <tr>

    <td width="43%">Name</td>

    <td width="57%"><?php echo $productName; ?></td>

  </tr>

  <tr>

    <td>SKU</td>

    <td><?php echo $productSKU; ?></td>

  </tr>

  <tr>

    <td>Color</td>

    <td><?php echo $productColor; ?></td>

  </tr>

  <tr>

    <td>Quantity</td>

    <td><?php echo $productQuantity; ?></td>

  </tr>

  <tr>

    <td>&nbsp;</td>

    <td>&nbsp;</td>

  </tr>

  <tr>

    <td>Price</td>

    <td>$<?php echo $productUnitPrice; ?></td>

  </tr>

  <tr>

    <td>SubTotal</td>

    <td>$<?php echo $subTotal; ?></td>

  </tr>

  <tr>

    <td>Tax</td>

    <td><?php echo $taxAmount; ?>%</td>

  </tr>

  <tr>

    <td>Order Total</td>

    <td>$<?php echo $Total; ?></td>

  </tr>

  <tr>

    <td colspan="2">&nbsp;</td>

    </tr>

  <tr>

    <td colspan="2">In order to process your order please complete the following.</td>

    </tr>

  <tr>

    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields"> First Name</td>

    <td>

      <input name="txtbxFName" type="text" class="fm2" id="txtbxFName">

    </td>

  </tr>

  <tr>

    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields"> Last Name</td>

    <td><input name="txtbxLName" type="text" class="fm2" id="txtbxLName"></td>

  </tr>

  <tr>

    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields">Phone (xxx) xxx-xxxx</td>

    <td><input name="txtbxPhone" type="text" class="fm2" id="txtbxPhone"></td>

  </tr>

  <tr>

    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields">Email Address</td>

    <td><input name="txtbxEmail" type="text" class="fm2" id="txtbxEmail"></td>

  </tr>

  <tr>

    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields"> Address</td>

    <td><input name="txtbxAddress1" type="text" class="fm2" id="txtbxAddress1"></td>

  </tr>

  <tr>

    <td>Address</td>

    <td><input name="txtbxAddress2" type="text" class="fm2" id="txtbxAddress2"></td>

  </tr>

  <tr>

    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields"> City</td>

    <td><input name="txtbxCity" type="text" class="fm2" id="txtbxCity"></td>

  </tr>

  <tr>

    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields"> State</td>

    <td>

    <select name="ddlState" size="1" class="fm2">

	<option value="AK" selected>AK</option>

	<option value="AL">AL</option>

	<option value="AR">AR</option>

	<option value="AZ">AZ</option>

	<option value="CA">CA</option>

	<option value="CO">CO</option>

	<option value="CT">CT</option>

	<option value="DC">DC</option>

	<option value="DE">DE</option>

	<option value="FL">FL</option>

	<option value="GA">GA</option>

	<option value="HI">HI</option>

	<option value="IA">IA</option>

	<option value="ID">ID</option>

	<option value="IL">IL</option>

	<option value="IN">IN</option>

	<option value="KS">KS</option>

	<option value="KY">KY</option>

	<option value="LA">LA</option>

	<option value="MA">MA</option>

	<option value="MD">MD</option>

	<option value="ME">ME</option>

	<option value="MI">MI</option>

	<option value="MN">MN</option>

	<option value="MO">MO</option>

	<option value="MS">MS</option>

	<option value="MT">MT</option>

	<option value="NC">NC</option>

	<option value="ND">ND</option>

	<option value="NE">NE</option>

	<option value="NH">NH</option>

	<option value="NJ">NJ</option>

	<option value="NM">NM</option>

	<option value="NV">NV</option>

	<option value="NY">NY</option>

	<option value="OH">OH</option>

	<option value="OK">OK</option>

	<option value="OR">OR</option>

	<option value="PA">PA</option>

	<option value="RI">RI</option>

	<option value="SC">SC</option>

	<option value="SD">SD</option>

	<option value="TN">TN</option>

	<option value="TX">TX</option>

	<option value="UT">UT</option>

	<option value="VA">VA</option>

	<option value="VT">VT</option>

	<option value="WA">WA</option>

	<option value="WI">WI</option>

	<option value="WV">WV</option>

	<option value="WY">WY</option>

</select>

    </td>

  </tr>

  <tr>

    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields"> Zip</td>

    <td><input name="txtbxZip" type="text" class="fm2" id="txtbxZip" maxlength="5"></td>

  </tr>

  <tr>

    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields"> Credit Card Type</td>

    <td>

    <select name="ddlCCType" class="fm2" id="ddlCCType" >

                <option value="001" selected>Visa</option>

                <option value="002">MasterCard</option>

                <option value="003">American Express</option>

                <option value="004">Discover</option>

                </select>

    </td>

  </tr>

  <tr>

    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields"> Credit Card No.</td>

    <td><input name="txtbxCCNum" type="text" class="fm2" id="txtbxCCNum" maxlength="20"></td>

  </tr>

  <tr>

    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields"> CCV No.</td>

    <td><input name="txtbxCCVNum" type="text" class="fm2" id="txtbxCCVNum" size="5" maxlength="4"></td>

  </tr>

  <tr>

    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields"> CC Expiration Date</td>

    <td>

    <SELECT NAME="ddlCCExpireDate" class="fm2">

      <option value="01">01

      <option value="02">02

      <option value="03">03

      <option value="04">04

      <option value="05">05

      <option value="06">06

      <option value="07">07

      <option value="08">08

      <option value="09">09

      <option value="10">10

      <option value="11">11

      <option value="12">12

      </SELECT>

&nbsp;&nbsp;

    <select name="ddlCCExpireYear" size="1" class="fm2">

                  <option value="2009">2009</option>

                  <option value="2010">2010</option>

                  <option value="2011">2011</option>

                  <option value="2012">2012</option>

                  <option value="2013">2013</option>

                  <option value="2014">2014</option>

                  <option value="2015">2015</option>

                  <option value="2016">2016</option>

                  <option value="2017">2017</option>

                  <option value="2018">2018</option></select>

                  </td>

  </tr>

  <tr>

    <td colspan="2">&nbsp;</td>

    </tr>

  <tr>

    <td colspan="2">

	<input type="hidden" name="placeOrder" value=1>

    <input name="btnSubmit" type="submit" class="fmsend" id="btnSubmit" value="Order Now" onClick="return ValidateForm()">

    </td>

    </tr>

  <tr>

    <td colspan="2">&nbsp;</td>

  </tr>

  </table>

</form>

Open in new window

0
 
LVL 9

Expert Comment

by:xBellox
ID: 24858670
I don't know if I understand it right, but you want use the same method of page 1 to make sure that you are processing the page 2.



At form of page2:
 <input type="hidden" name="secondpage"  value="1">

Then if

$_POST['productpage']==1 it cames from page 1, and if

$_POST['secondpage']==1, It means that it was already processed by page2






0
 
LVL 14

Expert Comment

by:profya
ID: 24858702
The trick is as follows:
I used the hidden input founded in the first page to redirect the user to the first page line 32. And to allow you to use the order form for getting the information and processing the order at the same time, I added a hidden input named placeOrder, line 254.
When your order page called, it checks if the order form posted, if no it checks if the user has filled the first name or not, if not filled, it redirects the user back to the first form.
If the order form posted, this means than the user has passed the first form then filled the order form and submitted it, in the case process the order.
I hope this helps.
0
 

Author Comment

by:fwstealer
ID: 24858837
profya, when I use the forms above the 2nd page has nothing on it.
0
 

Author Comment

by:fwstealer
ID: 24858849
meaning the 2ndpage the order summary is empty; it should show the data from the previous page
0
 
LVL 14

Expert Comment

by:profya
ID: 24859038
No, you have to catch the inputs entered in form two and echo them. Place this for example between lines 42 and 43:
echo $_POST['txtbxFName'], $_POST['txtbxLName'], $_POST['txtbxPhone'];
Then post your order.
0
 

Author Comment

by:fwstealer
ID: 24859042
duh - noticed the global variables are not there.

So I added them and tried to test the page.

<?php
      //global variables
      $productName = $_POST['productName'];
      $productSKU = $_POST['productSKU'];
      $productDescription = $_POST['description'];
      $productColor = $_POST['ddlColor'];
      $productQuantity = $_POST['txtbxQuantity'];
      $productUnitPrice = $_POST['unitPrice'];
      $subTotal = ($productUnitPrice * $productQuantity);
      $taxAmount = .07;
      $Total = ($subTotal * $taxAmount) + $subTotal;

if (!isset($_POST['placeOrder']))
{
      $productpage = @$_POST['productpage'];
      //ensure that this page is coming from a product page; if not then it is redirected to the referring page
      if ($productpage != "1")
      {
            //this must take place before any page output to the browser
            header("Location: start.html");
            exit();
      }
}
else if ($_POST['placeOrder']==1)//Process order
{
      //populate the form with the returned values
      $txtbxFName = $_POST['txtbxFName'];
      echo $txtbxFName; //returns the name
      echo $Total; //returns 0. Why not return the global variable value that was captured from the 1st page and loaded in the 2nd page form?
}
?>

i'm setting the global variables so why are they not seen as global to the script?
0
 

Author Comment

by:fwstealer
ID: 24859112
i also change the following as I'm going to try and use the orderform as a generic page to catch all and will have other product page forms sending data to it.

<?php
      //global variables
      $ref = getenv("HTTP_REFERER");

            header("Location: $ref");
0
 
LVL 14

Expert Comment

by:profya
ID: 24859199
No problem as I can see, however, this may fail if I visited the first form and then moved to the order form without posting the first page form. In addition to the hidden input this seems good.
0
 

Author Comment

by:fwstealer
ID: 24859277
here is what I'm doing now.

<?php
      //global variables
      $ref = getenv("HTTP_REFERER");

      $productName = $_POST['productName'];
      $productSKU = $_POST['productSKU'];
      $productDescription = $_POST['description'];
      $productColor = $_POST['ddlColor'];
      $productQuantity = $_POST['txtbxQuantity'];
      $productUnitPrice = $_POST['unitPrice'];
      $subTotal = ($productUnitPrice * $productQuantity);
      $taxAmount = .07;
      $Total = ($subTotal * $taxAmount) + $subTotal;

      $txtbxFName = $_POST['txtbxFName'];
      $txtbxLName = $_POST['txtbxLName'];
      $txtbxPhone = $_POST['txtbxPhone'];
      
if (!isset($_POST['placeOrder']))
{
      $productpage = @$_POST['productpage'];
      //ensure that this page is coming from a product page; if not then it is redirected to the referring page
      if ($productpage != "1")
      {
            //this must take place before any page output to the browser
            header("Location: $ref");
            exit();
      }
}
else if ($_POST['placeOrder']==1)//Process order
{
      //populate the form with the returned values
      echo $Total; //returns 0. Why not return the global variable value that was captured from the 1st page and loaded in the 2nd page form?
}
?>

<form id="orderform" name="orderform" action="<?php echo $_Server['PHP_SELF']; ?>" method="post">
 <table border="0" align="left" cellpadding="2" cellspacing="0">
  <tr>
    <td colspan="2" align="left" class="larger">Order Summary</td>
    </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
    </tr>
  <tr>
    <td width="43%">Name</td>
    <td width="57%"><?php echo $productName; ?></td>
  </tr>
  <tr>
    <td>SKU</td>
    <td><?php echo $productSKU; ?></td>
  </tr>
  <tr>
    <td>Color</td>
    <td><?php echo $productColor; ?></td>
  </tr>
  <tr>
    <td>Quantity</td>
    <td><?php echo $productQuantity; ?></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>Price</td>
    <td>$<?php echo $productUnitPrice; ?></td>
  </tr>
  <tr>
    <td>SubTotal</td>
    <td>$<?php echo $subTotal; ?></td>
  </tr>
  <tr>
    <td>Tax</td>
    <td><?php echo $taxAmount; ?>%</td>
  </tr>
  <tr>
    <td>Order Total</td>
    <td>$<?php echo $Total; ?></td>
  </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
    </tr>
  <tr>
    <td colspan="2">In order to process your order please complete the following.</td>
    </tr>
  <tr>
    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields"> First Name</td>
    <td>
      <input name="txtbxFName" type="text" class="fm2" id="txtbxFName" value="<?php echo $txtbxFName; ?>">
    </td>
  </tr>
  <tr>
    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields"> Last Name</td>
    <td><input name="txtbxLName" type="text" class="fm2" id="txtbxLName" value="<?php echo $txtbxLName; ?>"></td>
  </tr>
  <tr>
    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields">Phone (xxx) xxx-xxxx</td>
    <td><input name="txtbxPhone" type="text" class="fm2" id="txtbxPhone" value="<?php echo $txtbxPhone; ?>"></td>
  </tr>


Why are the order summary values returning empty and 0 data? The variables are global, right?
0
 
LVL 14

Expert Comment

by:profya
ID: 24859326
The global variables has been placed in the wrong location. They should appear after the order form has been submitted, because before that they are nothing.
<?php

      //global variables

      $ref = getenv("HTTP_REFERER");

if (!isset($_POST['placeOrder']))

{

      $productpage = @$_POST['productpage'];

      //ensure that this page is coming from a product page; if not then it is redirected to the referring page

      if ($productpage != "1")

      {

            //this must take place before any page output to the browser

            header("Location: $ref");

            exit();

      }

}

else if ($_POST['placeOrder']==1)//Process order

{

	  //Those variables should be here because they are defined after the form has been posted.

      $productName = $_POST['productName'];

      $productSKU = $_POST['productSKU'];

      $productDescription = $_POST['description'];

      $productColor = $_POST['ddlColor'];

      $productQuantity = $_POST['txtbxQuantity'];

      $productUnitPrice = $_POST['unitPrice'];

      $subTotal = ($productUnitPrice * $productQuantity);

      $taxAmount = .07;

      $Total = ($subTotal * $taxAmount) + $subTotal;
 

      $txtbxFName = $_POST['txtbxFName'];

      $txtbxLName = $_POST['txtbxLName'];

      $txtbxPhone = $_POST['txtbxPhone'];

      echo $Total; //returns 0. Why not return the global variable value that was captured from the 1st page and loaded in the 2nd page form?

}

?>
 

<form id="orderform" name="orderform" action="<?php echo $_Server['PHP_SELF']; ?>" method="post">

 <table border="0" align="left" cellpadding="2" cellspacing="0">

  <tr>

    <td colspan="2" align="left" class="larger">Order Summary</td>

    </tr>

  <tr>

    <td colspan="2">&nbsp;</td>

    </tr>

  <tr>

    <td width="43%">Name</td>

    <td width="57%"><?php echo $productName; ?></td>

  </tr>

  <tr>

    <td>SKU</td>

    <td><?php echo $productSKU; ?></td>

  </tr>

  <tr>

    <td>Color</td>

    <td><?php echo $productColor; ?></td>

  </tr>

  <tr>

    <td>Quantity</td>

    <td><?php echo $productQuantity; ?></td>

  </tr>

  <tr>

    <td>&nbsp;</td>

    <td>&nbsp;</td>

  </tr>

  <tr>

    <td>Price</td>

    <td>$<?php echo $productUnitPrice; ?></td>

  </tr>

  <tr>

    <td>SubTotal</td>

    <td>$<?php echo $subTotal; ?></td>

  </tr>

  <tr>

    <td>Tax</td>

    <td><?php echo $taxAmount; ?>%</td>

  </tr>

  <tr>

    <td>Order Total</td>

    <td>$<?php echo $Total; ?></td>

  </tr>

  <tr>

    <td colspan="2">&nbsp;</td>

    </tr>

  <tr>

    <td colspan="2">In order to process your order please complete the following.</td>

    </tr>

  <tr>

    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields"> First Name</td>

    <td>

      <input name="txtbxFName" type="text" class="fm2" id="txtbxFName" value="<?php echo $txtbxFName; ?>">

    </td>

  </tr>

  <tr>

    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields"> Last Name</td>

    <td><input name="txtbxLName" type="text" class="fm2" id="txtbxLName" value="<?php echo $txtbxLName; ?>"></td>

  </tr>

  <tr>

    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields">Phone (xxx) xxx-xxxx</td>

    <td><input name="txtbxPhone" type="text" class="fm2" id="txtbxPhone" value="<?php echo $txtbxPhone; ?>"></td>

  </tr>

Open in new window

0
 

Author Comment

by:fwstealer
ID: 24859407
That seems odd to embed global variables in an if condition. So I did that and now when the page load the order summary is empty and not showing data. Doesn't this just make the global variables now local variables?
0
 
LVL 14

Expert Comment

by:profya
ID: 24859456
We are not using any kind of global variables, when the order form is submitted, we get values from $_POST, we may need to make sure that all variables has been successfully sent, by echoing $productName, $productSKU  etc. When everything is fine, then we calculate the total. Then we are ready to do the payment process.
If there is something wrong we need to tackle it. You can add:
error_reporting(E_ALL);
as the first php code line, this shows you hidden errors.
0
 

Author Comment

by:fwstealer
ID: 24859660
take a look at this code. you'll see that some of the variables are needed to capture data from the 1st page. however the data from those variables are not being maintained at all.

<?php
//return all errors
error_reporting(E_ALL); //so far no errors returned

      //local script variables
      $ref = getenv("HTTP_REFERER");
      //below are needed to capture the data from page 1 with comments to show data coming into this page
            $productName = $_POST['productName']; //Sunshine Candy
            $productSKU = $_POST['productSKU']; //101candy
            $productDescription = $_POST['description']; //not used
            $productColor = $_POST['ddlColor']; //green
            $productQuantity = $_POST['txtbxQuantity']; //123
            $productUnitPrice = $_POST['unitPrice']; // $1.00
            $subTotal = ($productUnitPrice * $productQuantity); //$123
            $taxAmount = .07; //0.07%
            $Total = ($subTotal * $taxAmount) + $subTotal; //$131.61
if (!isset($_POST['placeOrder']))
{
      $productpage = @$_POST['productpage'];
      //ensure that this page is coming from a product page; if not then it is redirected to the referring page
      if ($productpage != "1")
      {
            //this must take place before any page output to the browser
            header("Location: $ref");
            exit();
      }
}
else if ($_POST['placeOrder']==1)//Process order
{
      //supposed to be here to capture the form post from this page and it shows the current values - they don't match
            $productName = $_POST['productName']; //empty
            $productSKU = $_POST['productSKU']; //empty
            $productDescription = $_POST['description']; //not used
            $productColor = $_POST['ddlColor']; //empty
            $productQuantity = $_POST['txtbxQuantity']; //empty
            $productUnitPrice = $_POST['unitPrice']; //$
            $subTotal = ($productUnitPrice * $productQuantity); //$0
            $taxAmount = .07; //0.07%
            $Total = ($subTotal * $taxAmount) + $subTotal; //$0

      $txtbxFName = $_POST['txtbxFName'];
      $txtbxLName = $_POST['txtbxLName'];
      $txtbxPhone = $_POST['txtbxPhone'];
      $txtbxEmail = $_POST['txtbxEmail'];
      $txtbxAddress1 = $_POST['txtbxAddress1'];
      $txtbxAddress2 = $_POST['txtbxAddress2'];                                    
      $txtbxCity = $_POST['txtbxCity'];
      $ddlState = $_POST['ddlState'];
}
?>
0
 
LVL 14

Expert Comment

by:profya
ID: 24859781
Ok. I got it, data passed from the first page can be saved in hidden inputs or in the session. However, using hidden input is better as I can see. In this case we add hidden inputs similar to those in the first page. we then keep their values to use it when the order form is posted, for example:
We add this to the order form
<input type="hidden" name="name_of_input_in_the_1stpage" value="<?php echo @$_POST['name_of_input_in_the_1stpage'];?>"

This input will be posted normally along with other order form inputs.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:fwstealer
ID: 24859988
cool; making progress; however there are still some empty values.
color -
quantity -
price -
subtotal -
order total -

below is my code revised.
<?php
//return all errors
error_reporting(E_ALL); //so far no errors returned
      //local script variables
      $ref = getenv("HTTP_REFERER");
      //below are needed to capture the data from page 1 with comments to show data coming into this page
      $productName = $_POST['productName']; //Sunshine Candy
      $productSKU = $_POST['productSKU']; //101candy
      $productDescription = $_POST['description']; //not used
      $productColor = $_POST['ddlColor']; //green
      $productQuantity = $_POST['txtbxQuantity']; //123
      $productUnitPrice = $_POST['unitPrice']; // $1.00
      $subTotal = ($productUnitPrice * $productQuantity); //$123
      $taxAmount = .07; //0.07%
      $Total = ($subTotal * $taxAmount) + $subTotal; //$131.61
if (!isset($_POST['placeOrder']))
{
      $productpage = @$_POST['productpage'];
      //ensure that this page is coming from a product page; if not then it is redirected to the referring page
      if ($productpage != "1")
      {
            //this must take place before any page output to the browser
            header("Location: $ref");
            exit();
      }
}
else if ($_POST['placeOrder']==1)//Process order
{
      $txtbxFName = $_POST['txtbxFName'];
      $txtbxLName = $_POST['txtbxLName'];
      $txtbxPhone = $_POST['txtbxPhone'];
      $txtbxEmail = $_POST['txtbxEmail'];
      $txtbxAddress1 = $_POST['txtbxAddress1'];
      $txtbxAddress2 = $_POST['txtbxAddress2'];                                    
      $txtbxCity = $_POST['txtbxCity'];
      $ddlState = $_POST['ddlState'];
      $txtbxZip = $_POST['txtbxZip'];
      $ddlCCType = $_POST['ddlCCType'];
      $txtbxCCNum = $_POST['txtbxCCNum'];
      $txtbxCCVNum = $_POST['txtbxCCVNum'];
      $ddlCCExpireDate = $_POST['ddlCCExpireDate'];
      $ddlCCExpireYear = $_POST['ddlCCExpireYear'];
      //
}
?>
<!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-Type" content="text/html; charset=utf-8" />
<title>order form</title>
</head>
<body>
<form id="orderform" name="orderform" action="<?php echo $_Server['PHP_SELF']; ?>" method="post">
 <table border="0" align="left" cellpadding="2" cellspacing="0">
  <tr>
    <td colspan="2" align="left" class="larger">Order Summary</td>
    </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
    </tr>
  <tr>
    <td width="43%">Name</td>
    <td width="57%"><?php echo $productName; ?></td>
  </tr>
  <tr>
    <td>SKU</td>
    <td><?php echo $productSKU; ?></td>
  </tr>
  <tr>
    <td>Color</td>
    <td><?php echo $productColor; ?></td>
  </tr>
  <tr>
    <td>Quantity</td>
    <td><?php echo $productQuantity; ?></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>Price</td>
    <td>$<?php echo $productUnitPrice; ?></td>
  </tr>
  <tr>
    <td>SubTotal</td>
    <td>$<?php echo $subTotal; ?></td>
  </tr>
  <tr>
    <td>Tax</td>
    <td><?php echo $taxAmount; ?>%</td>
  </tr>
  <tr>
    <td>Order Total</td>
    <td>$<?php echo $Total; ?></td>
  </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
    </tr>
  <tr>
    <td colspan="2">In order to process your order please complete the following.</td>
    </tr>
  <tr>
    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields"> First Name</td>
    <td>
      <input name="txtbxFName" type="text" class="fm2" id="txtbxFName" value="<?php echo $txtbxFName; ?>">
    </td>
  </tr>
  <tr>
    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields"> Last Name</td>
    <td><input name="txtbxLName" type="text" class="fm2" id="txtbxLName" value="<?php echo $txtbxLName; ?>"></td>
  </tr>
  <tr>
    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields">Phone (xxx) xxx-xxxx</td>
    <td><input name="txtbxPhone" type="text" class="fm2" id="txtbxPhone" value="<?php echo $txtbxPhone; ?>"></td>
  </tr>
  <tr>
    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields">Email Address</td>
    <td><input name="txtbxEmail" type="text" class="fm2" id="txtbxEmail" value="<?php echo $txtbxEmail; ?>"></td>
  </tr>
  <tr>
    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields"> Address</td>
    <td><input name="txtbxAddress1" type="text" class="fm2" id="txtbxAddress1" value="<?php echo $txtbxAddress1; ?>"></td>
  </tr>
  <tr>
    <td>Address</td>
    <td><input name="txtbxAddress2" type="text" class="fm2" id="txtbxAddress2" value="<?php echo $txtbxAddress2; ?>"></td>
  </tr>
  <tr>
    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields"> City</td>
    <td><input name="txtbxCity" type="text" class="fm2" id="txtbxCity" value="<?php echo $txtbxCity; ?>"></td>
  </tr>
  <tr>
    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields"> State</td>
    <td>
    <select name="ddlState" size="1" class="fm2">
      <option value="AK" selected>AK</option>
      <option value="AL">AL</option>
      <option value="AR">AR</option>
      <option value="AZ">AZ</option>
      <option value="CA">CA</option>
      <option value="CO">CO</option>
      <option value="CT">CT</option>
      <option value="DC">DC</option>
      <option value="DE">DE</option>
      <option value="FL">FL</option>
      <option value="GA">GA</option>
      <option value="HI">HI</option>
      <option value="IA">IA</option>
      <option value="ID">ID</option>
      <option value="IL">IL</option>
      <option value="IN">IN</option>
      <option value="KS">KS</option>
      <option value="KY">KY</option>
      <option value="LA">LA</option>
      <option value="MA">MA</option>
      <option value="MD">MD</option>
      <option value="ME">ME</option>
      <option value="MI">MI</option>
      <option value="MN">MN</option>
      <option value="MO">MO</option>
      <option value="MS">MS</option>
      <option value="MT">MT</option>
      <option value="NC">NC</option>
      <option value="ND">ND</option>
      <option value="NE">NE</option>
      <option value="NH">NH</option>
      <option value="NJ">NJ</option>
      <option value="NM">NM</option>
      <option value="NV">NV</option>
      <option value="NY">NY</option>
      <option value="OH">OH</option>
      <option value="OK">OK</option>
      <option value="OR">OR</option>
      <option value="PA">PA</option>
      <option value="RI">RI</option>
      <option value="SC">SC</option>
      <option value="SD">SD</option>
      <option value="TN">TN</option>
      <option value="TX">TX</option>
      <option value="UT">UT</option>
      <option value="VA">VA</option>
      <option value="VT">VT</option>
      <option value="WA">WA</option>
      <option value="WI">WI</option>
      <option value="WV">WV</option>
      <option value="WY">WY</option>
</select>
    </td>
  </tr>
  <tr>
    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields"> Zip</td>
    <td><input name="txtbxZip" type="text" class="fm2" id="txtbxZip" maxlength="5" value="<?php echo $txtbxZip; ?>"></td>
  </tr>
  <tr>
    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields"> Credit Card Type</td>
    <td>
    <select name="ddlCCType" class="fm2" id="ddlCCType" >
                <option value="001" selected>Visa</option>
                <option value="002">MasterCard</option>
                <option value="003">American Express</option>
                <option value="004">Discover</option>
                </select>
    </td>
  </tr>
  <tr>
    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields"> Credit Card No.</td>
    <td><input name="txtbxCCNum" type="text" class="fm2" id="txtbxCCNum" maxlength="20" value="<?php echo $txtbxCCNum; ?>"></td>
  </tr>
  <tr>
    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields"> CCV No.</td>
    <td><input name="txtbxCCVNum" type="text" class="fm2" id="txtbxCCVNum" size="5" maxlength="4" value="<?php echo $txtbxCCVNum; ?>"></td>
  </tr>
  <tr>
    <td><IMG SRC="images/tick.gif" WIDTH="10" HEIGHT="12" ALT="Required form fields"> CC Expiration Date</td>
    <td>
    <SELECT NAME="ddlCCExpireDate" class="fm2">
      <option value="01">01
      <option value="02">02
      <option value="03">03
      <option value="04">04
      <option value="05">05
      <option value="06">06
      <option value="07">07
      <option value="08">08
      <option value="09">09
      <option value="10">10
      <option value="11">11
      <option value="12">12
      </SELECT>
&nbsp;&nbsp;
    <select name="ddlCCExpireYear" size="1" class="fm2">
                  <option value="2009">2009</option>
                  <option value="2010">2010</option>
                  <option value="2011">2011</option>
                  <option value="2012">2012</option>
                  <option value="2013">2013</option>
                  <option value="2014">2014</option>
                  <option value="2015">2015</option>
                  <option value="2016">2016</option>
                  <option value="2017">2017</option>
                  <option value="2018">2018</option></select>
                  </td>
  </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
    </tr>
  <tr>
    <td colspan="2">
        <input type="hidden" name="productName" value="<?php echo $productName; ?>">
        <input type="hidden" name="productSKU" value="<?php echo $productSKU; ?>">
        <input type="hidden" name="productDescription" value="<?php echo $productDescription; ?>">
        <input type="hidden" name="productColor" value="<?php echo $productColor; ?>">
        <input type="hidden" name="productQuantity" value="<?php echo $productQuantity; ?>">
        <input type="hidden" name="unitPrice" value="<?php echo $unitPrice; ?>">
        <input type="hidden" name="subTotal" value="<?php echo $subTotal; ?>">
        <input type="hidden" name="taxAmount" value="<?php echo $taxAmount; ?>">
        <input type="hidden" name="Total" value="<?php echo $Total; ?>">
      <input type="hidden" name="placeOrder" value=1>
    <input name="btnSubmit" type="submit" class="fmsend" id="btnSubmit" value="Order Now" >
    </td>
    </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
  </tr>
  </table>
</form>
</body>
</html>
0
 
LVL 14

Expert Comment

by:profya
ID: 24860110
Putting:
      $productName = $_POST['productName']; //Sunshine Candy
      $productSKU = $_POST['productSKU']; //101candy
      $productDescription = $_POST['description']; //not used
      $productColor = $_POST['ddlColor']; //green
      $productQuantity = $_POST['txtbxQuantity']; //123
      $productUnitPrice = $_POST['unitPrice']; // $1.00
      $subTotal = ($productUnitPrice * $productQuantity); //$123
      $taxAmount = .07; //0.07%
      $Total = ($subTotal * $taxAmount) + $subTotal; //$131.61

In the place you have selected is a bad habit, since this code is not controlled by anything, and it is going to run if the user has visited the orders page, because  the code checks if the user has filled page1's form comes later. Always put $_POST code when you are sure that there is a data has been sent from a page. Now, you should put the above code in a block of else of the following IF statement:
if ($productpage != "1")
      {
            //this must take place before any page output to the browser
            header("Location: $ref");
            exit();
      }

else
{
      $productName = $_POST['productName']; //Sunshine Candy
      $productSKU = $_POST['productSKU']; //101candy
      $productDescription = $_POST['description']; //not used
      $productColor = $_POST['ddlColor']; //green
      $productQuantity = $_POST['txtbxQuantity']; //123
      $productUnitPrice = $_POST['unitPrice']; // $1.00
      $subTotal = ($productUnitPrice * $productQuantity); //$123
      $taxAmount = .07; //0.07%
      $Total = ($subTotal * $taxAmount) + $subTotal; //$131.61
}

This guarantees that this code will not run unless a form has been submitted from page1.
I'll tell you a good technique, when you submit page1 and you are now in page2, generate the HTML source and make sure that hidden inputs are holding the right values. If not, then we need to fix the problem from this stage.
0
 

Author Comment

by:fwstealer
ID: 24861602
okay, so i modified the php code:

<?php
//return all errors
error_reporting(E_ALL); //so far no errors returned
//local script variables
$ref = getenv("HTTP_REFERER");

if (!isset($_POST['placeOrder']))
{
      $productpage = @$_POST['productpage'];
      //ensure that this page is coming from a product page; if not then it is redirected to the referring page
      if ($productpage != "1")
      {
            //this must take place before any page output to the browser
            header("Location: $ref");
            exit();
      }
      else
      {
            //below are needed to capture the data from page 1 with comments to show data coming into this page
            $productName = $_POST['productName']; //Sunshine Candy
            $productSKU = $_POST['productSKU']; //101candy
            $productDescription = $_POST['description']; //not used
            $productColor = $_POST['ddlColor']; //green
            $productQuantity = $_POST['txtbxQuantity']; //123
            $productUnitPrice = $_POST['unitPrice']; // $1.00
            $subTotal = ($productUnitPrice * $productQuantity); //$123
            $taxAmount = .07; //0.07%
            $Total = ($subTotal * $taxAmount) + $subTotal; //$131.61
      }
}
else if ($_POST['placeOrder']==1)//Process order
{
      $txtbxFName = $_POST['txtbxFName'];
      $txtbxLName = $_POST['txtbxLName'];
      $txtbxPhone = $_POST['txtbxPhone'];
      $txtbxEmail = $_POST['txtbxEmail'];
      $txtbxAddress1 = $_POST['txtbxAddress1'];
      $txtbxAddress2 = $_POST['txtbxAddress2'];                                    
      $txtbxCity = $_POST['txtbxCity'];
      $ddlState = $_POST['ddlState'];
      $txtbxZip = $_POST['txtbxZip'];
      $ddlCCType = $_POST['ddlCCType'];
      $txtbxCCNum = $_POST['txtbxCCNum'];
      $txtbxCCVNum = $_POST['txtbxCCVNum'];
      $ddlCCExpireDate = $_POST['ddlCCExpireDate'];
      $ddlCCExpireYear = $_POST['ddlCCExpireYear'];
      //
}
?>

after the user leaves the 1st page and lands on the 2nd page the following data is populated and valid
<input type="hidden" name="productName" value="Sunshine Candy">
        <input type="hidden" name="productSKU" value="101candy">
        <input type="hidden" name="productDescription" value="Wonderful candy.">
        <input type="hidden" name="productColor" value="Green">
        <input type="hidden" name="productQuantity" value="123">
        <input type="hidden" name="productUnitPrice" value="1.00">
        <input type="hidden" name="subTotal" value="123">
        <input type="hidden" name="taxAmount" value="0.07">
        <input type="hidden" name="Total" value="131.61">
      <input type="hidden" name="placeOrder" value=1>

however, after i click the submit button on the 2nd page the following are not populated

<input type="hidden" name="productName" value="">
        <input type="hidden" name="productSKU" value="">
        <input type="hidden" name="productDescription" value="">
        <input type="hidden" name="productColor" value="">
        <input type="hidden" name="productQuantity" value="">
        <input type="hidden" name="productUnitPrice" value="">
        <input type="hidden" name="subTotal" value="">
        <input type="hidden" name="taxAmount" value="">
        <input type="hidden" name="Total" value="">
      <input type="hidden" name="placeOrder" value=1>

0
 
LVL 14

Expert Comment

by:profya
ID: 24861748
This because in when the form is submitted your variables are empty. Can you listen to me, please, please try ti change all hidden inputs we agreed on to get its value directly from the $_POST, for example:
        <input type="hidden" name="productName" value="<?php echo @$_POST['productName']; ?>">
        <input type="hidden" name="productSKU" value="<?php echo  @$_POST['productSKU']; ?>">
        <input type="hidden" name="productDescription" value="<?php echo @$_POST['description'];

and so forth, because without that, we may need to cache these values in a session or track each case and write a lot of code.
0
 

Author Comment

by:fwstealer
ID: 24862809
okay, here is what I've got thus far
<?php
//return all errors
error_reporting(E_ALL); //so far no errors returned
//local script variables
$ref = getenv("HTTP_REFERER");
if (!isset($_POST['placeOrder']))
{
      $productpage = @$_POST['productPage'];
      //ensure that this page is coming from a product page; if not then it is redirected to the referring page
      if ($productpage != "1")
      {
            //this must take place before any page output to the browser
            header("Location: $ref");
            exit();
      }
      else
      {
            //below are needed to capture the data from page 1 with comments to show data coming into this page
            $productName = $_POST['productName'];
            $productSKU = $_POST['productSKU'];
            $productDescription = $_POST['productDescription'];
            $productColor = $_POST['ddlColor'];
            $productQuantity = $_POST['txtbxQuantity'];
            $productUnitPrice = $_POST['productUnitPrice'];
            $subTotal = ($productUnitPrice * $productQuantity);
            $taxAmount = .07;
            $Total = ($subTotal * $taxAmount) + $subTotal;
      }
}
else if ($_POST['placeOrder']==1)//Process order
{
      $txtbxFName = $_POST['txtbxFName'];
      $txtbxLName = $_POST['txtbxLName'];
      $txtbxPhone = $_POST['txtbxPhone'];
      $txtbxEmail = $_POST['txtbxEmail'];
      $txtbxAddress1 = $_POST['txtbxAddress1'];
      $txtbxAddress2 = $_POST['txtbxAddress2'];                                    
      $txtbxCity = $_POST['txtbxCity'];
      $ddlState = $_POST['ddlState'];
      $txtbxZip = $_POST['txtbxZip'];
      $ddlCCType = $_POST['ddlCCType'];
      $txtbxCCNum = $_POST['txtbxCCNum'];
      $txtbxCCVNum = $_POST['txtbxCCVNum'];
      $ddlCCExpireDate = $_POST['ddlCCExpireDate'];
      $ddlCCExpireYear = $_POST['ddlCCExpireYear'];
      $productName = $_POST['productName'];
      $productSKU = $_POST['productSKU'];
      $productDescription = $_POST['productDescription'];
      $productColor = $_POST['productColor'];
      $productQuantity = $_POST['productQuantity'];
      $productUnitPrice = $_POST['productUnitPrice'];
      $subTotal = ($productUnitPrice * $productQuantity);
      $taxAmount = .07;
      $Total = ($subTotal * $taxAmount) + $subTotal;
}
?>
<input type="hidden" name="productName" value="<?php echo @$_POST['productName']; ?>">
        <input type="hidden" name="productSKU" value="<?php echo  @$_POST['productSKU']; ?>">
        <input type="hidden" name="productDescription" value="<?php echo  @$_POST['productDescription']; ?>">
        <input type="hidden" name="productColor" value="<?php echo @$_POST['ddlColor']; ?>">
        <input type="hidden" name="productQuantity" value="<?php echo @$_POST['txtbxQuantity']; ?>">
        <input type="hidden" name="productUnitPrice" value="<?php echo @$_POST['productUnitPrice']; ?>">
        <input type="hidden" name="subTotal" value="<?php echo $subTotal; ?>">
        <input type="hidden" name="taxAmount" value="<?php echo $taxAmount; ?>">
        <input type="hidden" name="Total" value="<?php echo $Total; ?>">
            <input type="hidden" name="placeOrder" value="1">


when I land on the 2nd page the form values are populated:
<input type="hidden" name="productName" value="Sunshine Candy">
        <input type="hidden" name="productSKU" value="101candy">
        <input type="hidden" name="productDescription" value="Wonderful candy.">
        <input type="hidden" name="productColor" value="Green">
        <input type="hidden" name="productQuantity" value="1234">
        <input type="hidden" name="productUnitPrice" value="1.00">
        <input type="hidden" name="subTotal" value="1234">
        <input type="hidden" name="taxAmount" value="0.07">
        <input type="hidden" name="Total" value="1320.38">
       <input type="hidden" name="placeOrder" value="1">

when I submit the form the following values are:
<input type="hidden" name="productName" value="Sunshine Candy">
        <input type="hidden" name="productSKU" value="101candy">
        <input type="hidden" name="productDescription" value="Wonderful candy.">
        <input type="hidden" name="productColor" value="">
        <input type="hidden" name="productQuantity" value="">
        <input type="hidden" name="productUnitPrice" value="1.00">
        <input type="hidden" name="subTotal" value="1234">
        <input type="hidden" name="taxAmount" value="0.07">
        <input type="hidden" name="Total" value="1320.38">
            <input type="hidden" name="placeOrder" value="1">

why are the two hidden values empty?
productColor
productQuantity

0
 
LVL 14

Expert Comment

by:profya
ID: 24862937
This is an exceptional case, it happens because the hidden input takes two values in different case, when the page is loaded for the first time and then when it is submitted, to handle this exceptional case replace the following lines:
<input type="hidden" name="productColor" value="<?php echo @$_POST['ddlColor']; ?>">
<input type="hidden" name="productQuantity" value="<?php echo @$_POST['txtbxQuantity']; ?>">
With:
<input type="hidden" name="productColor" value="<?php echo isset($_POST['ddlColor'])?$_POST['ddlColor']:@$_POST['productColor']; ?>">
<input type="hidden" name="productQuantity" value="<?php echo isset($_POST['txtbxQuantity'])?$_POST['txtbxQuantity']:$_POST['productQuantity']; ?>">

I hope this will fix the problem.
0
 

Author Comment

by:fwstealer
ID: 24862971
that worked on it as the values are maintained.
0
 
LVL 14

Expert Comment

by:profya
ID: 24863089
Any further problems?
0
 

Author Comment

by:fwstealer
ID: 24863647
the only one that I'd like to work on is the following:
I'd like to figure out how to get the dropdownlists to have the selected items that the user selected.

Other than that - THANK YOU!
0
 
LVL 14

Expert Comment

by:profya
ID: 24867311
Ok, let's say that your select name is ddlCCType and it holds values 1, 2, 3 or 4 then your code will be
<SELECT name=ddlCCType....
<option <?php if (@$_POST'ddlCCType']=="2009") echo "selected";?> value="2009">2009</option>
<option <?php if (@$_POST'ddlCCType']=="2008") echo "selected";?> value="2008">2008</option>
<option <?php if (@$_POST'ddlCCType']=="2007") echo "selected";?> value="2007">2007</option>

And so forth, the idea is to echo "selected" when the current value of $_POST'ddlCCType' matches the value of the option. We use @ to ignore errors in case the form has loaded for the first time and the $_POST['ddlICCType'] not yet set.
I hope this helps.
0
 

Author Comment

by:fwstealer
ID: 24868962
I tried that and the server produces a 500 server error; if I remove the option values it works fine.
0
 
LVL 14

Expert Comment

by:profya
ID: 24868978
This is very strange. Would you please send me the piece of code renders the select options?
0
 
LVL 14

Expert Comment

by:profya
ID: 24868997
PHP code errors do not cause such a problem. Are you using any .htaccess file to redirect pages or something alike?
0
 

Author Comment

by:fwstealer
ID: 24869038
i put it in my date ddl.

    <select name="ddlCCExpireYear" size="1" class="fm2">
          <option <?php if (@$_POST'ddlCCExpireYear']=="2009") echo "selected";?> value="2009">2009</option>
            <option <?php if (@$_POST'ddlCCExpireYear']=="2008") echo "selected";?> value="2008">2008</option>
            <option <?php if (@$_POST'ddlCCExpireYear']=="2007") echo "selected";?> value="2007">2007</option>

                  <option value="2010">2010</option>
                  <option value="2011">2011</option>
                  <option value="2012">2012</option>
                  <option value="2013">2013</option>
                  <option value="2014">2014</option>
                  <option value="2015">2015</option>
                  <option value="2016">2016</option>
                  <option value="2017">2017</option>
                  <option value="2018">2018</option>
     </select>

no .htaccess or redirect page. I'm running on vista, apache and php -- VAP. lol
0
 
LVL 14

Accepted Solution

by:
profya earned 500 total points
ID: 24869104
$_POST'ddlCCExpireYear'] to be $_POST['ddlCCExpireYear']
0
 

Author Closing Comment

by:fwstealer
ID: 31603693
Outstanding; so much assistance - just picked the last post from profya.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now