I have a Form that loads on a shopping cart page when the page first loads. Once the Form is filled and validated it submits ok then the shopping cart ‘Add to Cart’ button appears and the Form disappears. The script runs ok but when the page first loads I get the error ‘Undefined variable: clearform’ I can’t see any way to make this work other than declaring the variable clearform to $clearform = 'tom' ; after all the validation has been passed because if I do the Form uploads to the server but stays on the page without being replaces with the “Add to Cart” button.
Can anyone please help as I’m so stuck and wonder if there is a better method of doing this? This page by the way is used as an ‘Include.php’ page elsewhere on the site.
Thanks very much for any help
Best wishes
Brian
<Snip>
Code: Select all
<?PHP if ($clearform != 'tom' ) { ?>
Show Form and “Form Submit Button”
<? } else { ?>
Show “Add to Cart Button"Code: Select all
// if ($_POST && array_key_exists('addToCart',$_POST))
{
$pattern = '/^\w[-.\w]*@([-a-z0-9]+\.)+[a-z]{2,4}$/i';
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] )) {
// set error variables
$messageemail='';
//$error_email = '' ;
$error=array();
$error_email=array();
$message_fname = '';
$fname_error='';
$clearform = 'tomm' ;
//$fullname = $_POST['fullname'];
$details_error = '';
//$message_fname = $_POST['fullname'];
$trimmedGuestDetails = '';
//$trimmedGuestDetails = $_POST['GuestDetails'];
// if you use $email= ''; the error message will not go away even if the correct address is entered.
$email= $_POST['email'];
//Full Name Conditional
if (isset($_POST['fullname']) && !empty($_POST['fullname'])) {
$message_fname=trim(strip_tags($_POST['fullname']));
}else{
$fname_error = '<b>Required</b>';
}
if (!trim($message_fname) && !empty($_POST['fullname'])) {
$fname_error = '<b>Required!</b>';
}
// Check each field and build errors array if problems found
if (isset($_POST['GuestDetails']) && !empty($_POST['GuestDetails'])) {
$trimmedGuestDetails=trim(strip_tags($_POST['GuestDetails']));
}else {
$details_error = '<b>Message Required</b>';
}
if (!trim($trimmedGuestDetails) && !empty($_POST['GuestDetails'])) {
$details_error = '<b>Required!</b>';
}
// EmailConditional Statement
if (isset($_POST['email']) && !empty($_POST['email'])) {
}else{
$messageemail= '<b>Required</b>';
}
if (empty($_POST['email'])) {// validation of email if inserted otherwise ignore
} else {
if (!preg_match($pattern,$email)) $error_email['invalid'] = 'ERROR! Your email address seems to be invalid. <br> It should be similar to the following: info@me.com';
}
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
} //$clearform = 'tomm' ;
// If no errors, send email and redirect to acknowledgment page
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "addToCart")) {
if (!$fname_error && !$details_error)
if (!$fname_error && !$error_email)
if (!$fname_error && !$messageemail)
{
$clearform = 'tom' ; }
/* Send mail */
$insertSQL = sprintf("INSERT INTO tbl_embroidery (name, details) VALUES (%s, %s)",
GetSQLValueString("$message_fname", "text"),
GetSQLValueString("$trimmedGuestDetails", "text"));
mysql_select_db($database_snazzy, $snazzy);
$Result1 = mysql_query($insertSQL, $snazzy) or die(mysql_error());
}}}}
include("CWLibrary/CWFunProductOptions.php");
/* [ START ] DISPLAY PRODUCT */
if($rsCWGetProduct_recordCount != 0) {
$imageSRC = $imageRoot . $row_rsCWGetProductImage["prdctImage_FileName"];
$imagePath = expandPath($imageSRC);
?>
<!-- Display Common Product data -->
<table id="tableProductDetails">
<tr>
<td><?php if (file_exists($imagePath) && is_file($imagePath)){ ?>
<img src="<?php echo($imageSRC);?>" alt="<?php echo($row_rsCWGetProduct["product_Name"]);?>">
<?php }?></td>
<td valign="top"><!-- Anchor point for when form is submitted -->
<a name="skus"></a>
<h1><?php echo($row_rsCWGetProduct["product_Name"]);?></h1>
<p><?php echo($row_rsCWGetProduct["product_Description"]);?></p>
<!-- [ START ] SKUs DATA TABLE -->
<?php
if (strtolower($cartweaver->settings->detailsDisplay) != "tables") {
include("CWLibrary/CWFunPriceList.php");
echo(getPriceList($row_rsCWGetProduct["product_ID"], $cartweaver->settings->allowBackOrders, $cartweaver->db));
}
/* [ START ] == ERROR ALERTS and CONFIRMATION NOTICE ========================= */
if ($cartweaver->getCWError()){
/* If fields were left blank or in correct data entered, show "Field Alert" */
?>
<p><span class="errorMessage"><?php foreach($cartweaver->cwError as $key => $value) echo($value);?></span></p>
<?php
}
if ($urlResult >= 0) {
echo("<p><strong>* $urlResult");
if ($urlResult > 1 or $urlResult == 0) {
echo(" items ");
}else{
echo(" item ");
}
echo("added to your cart! * <a href=\"" . $cartweaver->settings->targetGoToCart . "?cartid=" . $_SESSION["CartId"] . "&returnurl=" . $cartweaver->thisPageQS . "\">[Go To Cart]</a></strong></p> ");
}
?>
<form action="<?php echo($cartweaver->thisPage . "?cartid=" . $_SESSION["CartId"]);?>" method="post" name="addToCart">
<?php cwProductOptions($productId);?>
<?PHP if ($clearform != 'tom' ) { ?>
<? echo 'Please enter the text you wish to have embroidered on your clothing <b>before</b> you make a quanty or size selection. ' ; ?>
<table>
<tr valign="baseline">
<td align="right" nowrap>* Your Full Name:
<?php
if (isset($fname_error) && !empty($fname_error)) {
echo $fname_error; } ?>
</td>
<td><input type="text" name="fullname" value="<?php if (isset($_POST['fullname'])) echo $_POST['fullname'];?>" size="32"></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap> Email:
<?php
if (isset($messageemail) && !empty($messageemail)) {
echo $messageemail; } ?>
</td>
<td><input type="text" name="email" value="<?php if (isset($_POST['email'])) echo $_POST['email'];?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right" valign="top">Embrodery details<br>
plus any<br>
other requests:<br>
<?php if (isset($details_error) && !empty($details_error)) {
echo $details_error; } else {
} ?></td>
<td><textarea name="GuestDetails" cols="40" rows="5" id="GuestDetails"><?php if (isset($_POST['GuestDetails'])) echo $_POST['GuestDetails'];?></textarea>
</td>
</tr>
<?php
if (isset($error_email)) {
foreach ($error_email as $key => $value) { ?>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td><? echo $value.'<br />';}} ?></td>
</tr>
</table>
<input name="MM_insert" type="submit" value="Send text now">
<input name="MM_insert" type="hidden" value="addToCart">
<? } else { ?>
<input name="submit" type="submit" value="Add to Cart" class="formButton"> <? };?>
<input name="prodId" type="hidden" value="<?php echo($productId);?>">
</form>
</td>
</tr>
<?php
if ($displayUpsell == 1){
/* If there are upsell products associsted with this Product, display them. */
if ($rsCWGetupsell_recordCount != 0) { echo("<tr>
<!-- <td> </td> -->
<td>
<br>");
if($rsCWGetupsell_recordCount > 1){
echo("You may also be interested in these products:");
}else{
echo("You may also be interested in this product:");
}
echo("<br>");
$rsCWGetupsell_currentRow = 0;
do {
$rsCWGetupsell_currentRow++;
echo("<a href=\"" . $cartweaver->thisPage . "?prodId=" . $row_rsCWGetupsell["upsell_relProdId"] . "\">" . $row_rsCWGetupsell["product_Name"] . "</a>");
if (($rsCWGetupsell_recordCount > 1) && ($rsCWGetupsell_recordCount != $rsCWGetupsell_currentRow)){ echo(", ");}
} while ($row_rsCWGetupsell = $cartweaver->db->db_fetch_assoc($rsCWGetupsell));
echo("</td>
</tr>");
}/* END IF - rsCWGetupsell.RecordCount NEQ 0 */
}/* END if ($displayUpsell == 1) */
?>
</table>
<?php
/* [ END ] DISPLAY PRODUCT */
}else{
echo("<p>No product selected.</p> ");
}
/* End Check for Product ID */
?>
<table width="800" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<p> </p>
<p> </p>
</td>
</tr>
</table>