Jump to content

Need Help with codeing


makepeace1
Go to solution Solved by WebStyles,

Recommended Posts

I followed a tutorial online to create a order form but it doesnt seem to work for me hopefully somone will be able to tell me what is wrong with it

 

index.html

<html>

<head>

	<meta name="WT.qs_dlk" content="UwtGSArIZ2cAAF74xF8AAAAb"/>

	<meta name="WT.qs_shmv" content="hv20130110-raker.sf.quinstreet.net"/>

	<meta name="inject_params" content="WT.qs_dlk=UwtGSArIZ2cAAF74xF8AAAAb&"/>

	<meta http-equiv="Set-Cookie" content="inject_params=WT.qs_dlk=UwtGSArIZ2cAAF74xF8AAAAb&; path=/;  domain=htmlgoodies.com;"/>
	<meta http-equiv="Set-Cookie" content="WMUUID=UwtGSArIZ2cAAF74xF8AAAAb; path=/;  domain=htmlgoodies.com;"/>

<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Acme Widgets  - Get Your Widgets Here!</title>
<script language=javascript>
<!--//



function dm(amount) 
{
  string = "" + amount;
  dec = string.length - string.indexOf('.');
  if (string.indexOf('.') == -1)
  return string + '.00';
  if (dec == 1)
  return string + '00';
  if (dec == 2)
  return string + '0';
  if (dec > 3)
  return string.substring(0,string.length-dec+3);
  return string;
}



function calculate()
{

  QtyA = 0;  QtyB = 0;  QtyC = 0;
  TotA = 0;  TotB = 0;  TotC = 0;

  PrcA = 1.25; PrcB = 2.35; PrcC = 3.45;

 
 
  if (document.ofrm.qtyA.value > "")
     { QtyA = document.ofrm.qtyA.value };
  document.ofrm.qtyA.value = eval(QtyA);  
 
  if (document.ofrm.qtyB.value > "")
     { QtyB = document.ofrm.qtyB.value };
  document.ofrm.qtyB.value = eval(QtyB);  
 
  if (document.ofrm.qtyC.value > "")
     { QtyC = document.ofrm.qtyC.value };
  document.ofrm.qtyC.value = eval(QtyC);
 
 
  TotA = QtyA * PrcA;
  document.ofrm.totalA.value = dm(eval(TotA));
 
  TotB = QtyB * PrcB;
  document.ofrm.totalB.value = dm(eval(TotB));
 
  TotC = QtyC * PrcC;
  document.ofrm.totalC.value = dm(eval(TotC));
 
 
  Totamt = 
     eval(TotA) +
     eval(TotB) +
     eval(TotC) ;
    
  document.ofrm.GrandTotal.value = dm(eval(Totamt));
  
} 


function validNum(theForm)
{
  var checkOK = "0123456789.,";
  var checkStr = theForm.qtyA.value;
  var allValid = true;
  var validGroups = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    if (ch == ".")
    {
      allNum += ".";
      decPoints++;
    }
    else if (ch == "," && decPoints != 0)
    {
      validGroups = false;
      break;
    }
    else if (ch != ",")
      allNum += ch;
  }
  if (!allValid)
  {
    alert("Please enter only digit characters in the \"Class A quantity\" field.");
    theForm.qtyA.focus();
    return (false);
  }

  if (decPoints > 1 || !validGroups)
  {
    alert("Please enter a valid number in the \"Class A quantity\" field.");
    theForm.qtyA.focus();
    return (false);
  }

  var checkOK = "0123456789.,";
  var checkStr = theForm.qtyB.value;
  var allValid = true;
  var validGroups = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    if (ch == ".")
    {
      allNum += ".";
      decPoints++;
    }
    else if (ch == "," && decPoints != 0)
    {
      validGroups = false;
      break;
    }
    else if (ch != ",")
      allNum += ch;
  }
  if (!allValid)
  {
    alert("Please enter only digit characters in the \"Class B quantity\" field.");
    theForm.qtyB.focus();
    return (false);
  }

  if (decPoints > 1 || !validGroups)
  {
    alert("Please enter a valid number in the \"Class B quantity\" field.");
    theForm.qtyA.focus();
    return (false);
  }

  var checkOK = "0123456789.,";
  var checkStr = theForm.qtyC.value;
  var allValid = true;
  var validGroups = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    if (ch == ".")
    {
      allNum += ".";
      decPoints++;
    }
    else if (ch == "," && decPoints != 0)
    {
      validGroups = false;
      break;
    }
    else if (ch != ",")
      allNum += ch;
  }
  if (!allValid)
  {
    alert("Please enter only digit characters in the \"Class C quantity\" field.");
    theForm.qtyC.focus();
    return (false);
  }

  if (decPoints > 1 || !validGroups)
  {
    alert("Please enter a valid number in the \"Class C quantity\" field.");
    theForm.qtyC.focus();
    return (false);
  }


  calculate();
  return (true);
} 

function Validate(theForm)
{

if (theForm.Name.value == "")
{
alert("Please enter a value for the \"Name\" field.");
theForm.FirstName.focus();
return (false);
}

if (theForm.Email.value == "")
{
alert("Please enter a value for the \"Email\" field.");
theForm.LastName.focus();
return (false);
}
 
return (true);
}

//-->
</script>



</head>

<body bgcolor="#FFFFCC">

<h2>The Acme Widget Company</h2>
<h3>Get Your Widgets Here!</h3>
<br />
<p>Please make your selections from the following choices:</p>

<form method="POST" action="submitted.php" onsubmit="return Validate(this)" name="ofrm">
	<p>Please tell us who you are (<font color="#FF0000">red</font> denotes 
	required information):</p>
	<table border="0" cellpadding="0" width="550" id="table1">
		<tr>
			<td width="340" align="right"><font color="#FF0000">Name</font></td>
			<td width="10"> </td>
			<td width="200"><input type="text" name="Name" size="30" tabindex="1"></td>
		</tr>
		<tr>
			<td width="340" align="right"><font color="#FF0000">Email</font> 
			(Your confirmation will be sent here): </td>
			<td width="10"> </td>
			<td width="200"><input type="text" name="Email" size="30" tabindex="1"></td>
		</tr>
		<tr>
			<td width="340" align="right">Other Contact Info:</td>
			<td width="10"> </td>
			<td width="200"><input type="text" name="OtherInfo" size="30" tabindex="1"></td>
		</tr>
		<tr>
			<td width="340" align="right"> </td>
			<td width="10"> </td>
			<td width="200"> </td>
		</tr>
	</table>
	<p>And tell us what you would like:</p>
	<table border="0" cellpadding="0" width="550" id="table2">
		<tr>
			<td width="250" height="31"><b>Item Description</b></td>
			<td align="center" width="100" height="31"><b>Quantity</b></td>
			<td align="right" height="31" width="60"><b>Price </b></td>
			<td align="right" height="31" width="140"><b>Total</b></td>
		</tr>
		<tr>
			<td width="250">Class "A" Widgets</td>
			<td align="center" width="100">
			<input type="text" name="qtyA" size="5" tabindex="5" onchange="return validNum(document.ofrm)"></td>
			<td align="right" width="60">1.25</td>
			<td align="right" width="140">
			<input type="text" name="totalA" size="12" tabindex="99" onchange="calculate()"></td>
		</tr>
		<tr>
			<td width="250">Class "B" Widgets</td>
			<td align="center" width="100">
			<input type="text" name="qtyB" size="5" tabindex="5" onchange="return validNum(document.ofrm)"></td>
			<td align="right" width="60">2.35</td>
			<td align="right" width="140">
			<input type="text" name="totalB" size="12" tabindex="99" onchange="calculate()"></td>
		</tr>
		<tr>
			<td width="250">Class "C" Widgets</td>
			<td align="center" width="100">
			<input type="text" name="qtyC" size="5" tabindex="5" onchange="return validNum(document.ofrm)"></td>
			<td align="right" width="60">3.45</td>
			<td align="right" width="140">
			<input type="text" name="totalC" size="12" tabindex="99" onchange="calculate()"></td>
		</tr>
		<tr>
			<td width="250"> </td>
			<td align="center" width="100"> </td>
			<td align="right" width="60"> </td>
			<td align="right" width="140"> </td>
		</tr>
		<tr>
			<td width="250">
			<p align="right"><b>TOTALS:</b></td>
			<td align="center" width="100"> </td>
			<td align="right" width="60"> </td>
			<td align="right" width="140">
			<input type="text" name="GrandTotal" size="15" tabindex="99" onchange="calculate()"></td>
		</tr>
		<tr>
			<td width="250"> </td>
			<td align="center" width="100"> </td>
			<td align="right" width="60"> </td>
			<td align="right" width="140"> </td>
		</tr>
	</table>
	<p> </p>
	<table border="0" cellpadding="0" width="550" id="table3">
		<tr>
			<td width="563">
			<p align="center">
			<input type="submit" value="Submit" name="subButton" tabindex="50">     
			<input type="reset" value="Reset" name="resetButton" tabindex="50"></td>
		</tr>
	</table>
	
	
</form>

<p> </p>
<p>If you have questions or difficulties with this order page,<br />
 please contact 
our Customer Service Department (see our Contacts page.)</p>


    <script language="JavaScript" type="text/javascript">
	var gDomain="www.qsstats.com";
	var gDcsId="dcs37pv2c00000oun93vypyva_4k6d";
	var gFpc="WT_FPC";
	var gConvert=true;
	var gFpcDom = "htmlgoodies.com";
	if ((typeof(gConvert) != "undefined") && gConvert && (document.cookie.indexOf(gFpc + "=") == -1) && (document.cookie.indexOf("WTLOPTOUT=")==-1)) {
	    document.write("<SCR"+"IPT TYPE='text/javascript' SRC='http"+(window.location.protocol.indexOf('https:')==0?'s':'')+"://"+gDomain+"/"+gDcsId+"/wtid.js"+"'><\/SCR"+"IPT>");
	}
	function dcsAdditionalParameters() {}
    </script>

    <script type="text/javascript" src="/imageserver/common/webtrends.js"></script>

    <noscript><img alt="" border="0" name="DCSIMG" width="1" height="1" src="http://www.qsstats.com/dcs37pv2c00000oun93vypyva_4k6d/njs.gif?dcsuri=/nojavascript&WT.js=No&WT.tv=8.0.2;WT.qs_dlk=UwtGSArIZ2cAAF74xF8AAAAb;" /></noscript> 
	
	</body>


</html>

and then this is the submitted.php file that the file submits to when i click submit it just says connecting

 <?php
//uncomment for debugging
//print_r($_POST);
 
//most sites have magic quotes on
//but if they do not, this code simulates magic quotes
if( !get_magic_quotes_gpc() )
{
    if( is_array($_POST) )
        $_POST = array_map('addslashes', $_POST);
}
 

//make sure there is data in the name and email fields
if( empty($_POST["Name"]) )
{
    $error["name"] = "Name is required.";
    $Name = "";
}
else
    $Name = $_POST["Name"];
 
if( empty($_POST["Email"]) )
{
    $error["email"] = "Email is required.";
    $Email = "";
}
else
    $Email = $_POST["Email"];
 
if( empty($_POST["OtherInfo"]) )
{
    $OtherInfo = "";
}
else
    $OtherInfo = $_POST["OtherInfo"];
 
  
//check to make sure the qty fields are whole numbers
//but only check if there was data entered
if( !empty($_POST["qtyA"]) )
{
    if( is_numeric($_POST["qtyA"]) && ( intval($_POST["qtyA"]) == floatval($_POST["qtyA"]) ) )
    {
        //we have a whole number
    }
    else
        $error["qtyA"] = "Please enter a whole number for Class A Widgets.";
}
 
if( !empty($_POST["qtyB"]) )
{
    if( is_numeric($_POST["qtyB"]) && ( intval($_POST["qtyB"]) == floatval($_POST["qtyB"]) ) )
    {
        //we have a whole number
    }
    else
        $error["qtyB"] = "Please enter a whole number for Class B Widgets.";
}
 
if( !empty($_POST["qtyC"]) )
{
    if( is_numeric($_POST["qtyC"]) && ( intval($_POST["qtyC"]) == floatval($_POST["qtyC"]) ) )
    {
        //we have a whole number
    }
    else
        $error["qtyC"] = "Please enter a whole number for Class C Widgets.";
}
 

//we should have at least 1 item ordered in the form
if( empty($_POST["qtyA"]) && empty($_POST["qtyB"]) && empty($_POST["qtyC"]) )
    $error["no_qty"] = "Please enter at least 1 item to order.";
 

if( is_array($error) )
{
 
    echo "An error occurred while processing your order.";
    echo "<br>\n";
    echo "Please check the following error messages carefully, then click back in your browser.";
    echo "<br>\n";
 
    while(list($key, $val) = each($error))
    {
        echo $val;
        echo "<br>\n";
    }
 
    //stop everything as we have errors and should not continue
    exit();
 
}
 
  
//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;
 
  
//we have our data, and now build up an email message to send
$mailto = "eliquid@getitcheap.co.uk";
$subject = "Web Order";
 
$body  = "The following confirms the details of your order:\n";
$body .= "\n\n";
$body .= "Name: " . $Name . "\n";
$body .= "Email: " . $Email . "\n";
$body .= "Other Contact Info: " . $OtherInfo . "\n";
$body .= "\n\n";
$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);
 
//we should state the order was sent
echo "The following information was sent.";
echo "<br>\n";
echo "<pre>\n";
echo $body;
echo "</pre>\n";

?> 

would someone be able to help me

thanks in advance

Edited by makepeace1
Link to comment
Share on other sites

 

did you get an email when I tested on my server with the following information?

 

Name: peterEmail: peter@domain.comOther Contact Info: noneClass A Widgets: (1 * 1.25) = 1.25Class B Widgets: (3 * 2.35) = 7.05Class C Widgets: (2 * 3.45) = 6.9TOTALS: 15.2

no didnt get an email with anything

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.