Hello Everyone,
As you may already be aware we are implementing a shopping cart script into Freeway. I’ve run into an issue with a PHP FormsToGo submit form and my shopping cart script being on the same page. I have already reached out and waiting to hear from FormsToGo and thought I would try here.
I’ve tested several things and found out the if I delete a section of my shopping cart script, the submit form works. Below I’ve listed the error message I get, problematic code from shopping cart and FormsToGo code. Does anyone have any suggestions.
ERROR MESSAGE:
Could not execute SQL query:
SElECT * FROM WHERE products_id = 18
CODE FROM SCRIPT (IF REMOVED SUMBIT FOR WORKS):
<?php
// using list because we want to control the layouts just in css
$pages = buildPageNumbers(mysql_num_rows($sql_result), $SETTINGS_DB['products_per_page'], $current, $SETTINGS["pages_delta"], $SETTINGS["pages_first_last"]);
$sql_result = mysql_query($sql, $connection) or die ('Could not execute SQL query:<br />'.$sql.'<br /><strong>'.mysql_error().'</strong>');
$rowCounter = 1;
$js = '';
while ($product = mysql_fetch_assoc($sql_result)) {
$pav = getAvailableProductAttributes($product['products_id']);
foreach ($pav as $key => $attr) {
asort($attr['values']);
$pav[$key] = $attr;
}
if ($SETTINGS_DB['products_layout'] == 1) { // LIST VIEW
?>
<?php
if ($rowCounter == $SETTINGS_DB['grid_columns']) {
echo '<div class="clear"></div>';
$rowCounter = 0;
}
}
$rowCounter++;
if (intval($product['digital']) != 1) {
$js .= 'getPrice(document.getElementById("productForm_'.intval($product['products_id']).'"), "selectClass_'.intval($product['products_id']).'", "'.$SETTINGS["installFolder"].'frontend/include/ajax_price.php");'."n";
}
}
?>
CODE FROM FORMS TO GO:
<?PHP
######################################################
# #
# Forms To Go 4.5.4 #
# http://www.bebosoft.com/ #
# #
######################################################
define('kOptional', true);
define('kMandatory', false);
define('kStringRangeFrom', 1);
define('kStringRangeTo', 2);
define('kStringRangeBetween', 3);
define('kYes', 'yes');
define('kNo', 'no');
error_reporting(E_ERROR | E_WARNING | E_PARSE);
ini_set('track_errors', true);
function ListArray($theArray) {
return @implode(", ", $theArray);
}
function DoStripSlashes($fieldValue) {
// temporary fix for PHP6 compatibility - magic quotes deprecated in PHP6
if ( function_exists( 'get_magic_quotes_gpc' ) && get_magic_quotes_gpc() ) {
if (is_array($fieldValue) ) {
return array_map('DoStripSlashes', $fieldValue);
} else {
return trim(stripslashes($fieldValue));
}
} else {
return $fieldValue;
}
}
function FilterCChars($theString) {
return preg_replace('/[x00-x1F]/', '', $theString);
}
function ProcessTextField(&$codeHtmlForm, $fieldName, $fieldValue) {
$tagPattern = '/(<input[^>]+name=['"]?Q' . $fieldName . 'E['"s]+[^>]*>)/i';
preg_match($tagPattern, $codeHtmlForm, $matches);
$htmlTag = $matches[1];
$valuePattern = '/value=['"]?[^'"]*['"]+/i';
$replacementPattern = 'value="' . $fieldValue . '" ';
if (preg_match($valuePattern, $htmlTag)) {
$htmlTagToReplace = preg_replace($valuePattern, $replacementPattern, $htmlTag);
} else {
$valuePattern = '/([^>/]*)([/]?>)/';
$replacementPattern = '1 value="' . $fieldValue . '" 2';
$htmlTagToReplace = preg_replace($valuePattern, $replacementPattern, $htmlTag);
}
$codeHtmlForm = preg_replace($tagPattern, $htmlTagToReplace, $codeHtmlForm);
}
function ProcessTextArea(&$codeHtmlForm, $fieldName, $fieldValue) {
$tagPattern = '/(<textarea[^>]+name=['"]?Q' . $fieldName . 'E['"s]+[^>]*)>(.*?)(</textarea>)/is';
$replacementPattern = '1>' . $fieldValue . '3';
$codeHtmlForm = preg_replace($tagPattern, $replacementPattern, $codeHtmlForm);
}
function ProcessCheckBoxes(&$codeHtmlForm, $fieldName, $fieldValues) {
# Get all check boxes tags with the fieldname
$tagPattern = '/(<input[^>]+name=['"]?Q' . $fieldName . 'E([]|)['"s]+[^>]*>)/i';
$numMatches = preg_match_all($tagPattern, $codeHtmlForm, $matches);
#Strip all the 'checked' attributes previously set
for ($cnt = 0; $cnt < $numMatches; $cnt++) {
$checkedPattern = '/([s]+checked="checked"|[s]+checked)([^>]*)>/i';
$replacementPattern = '2>';
$htmlTag = $matches[1][$cnt];
if (preg_match($checkedPattern, $htmlTag)) {
$htmlTagToUncheck = preg_replace($checkedPattern, $replacementPattern, $htmlTag);
$matches[1][$cnt] = $htmlTagToUncheck;
$codeHtmlForm = str_replace($htmlTag, $htmlTagToUncheck, $codeHtmlForm);
}
}
# Find the tags that must be checked
if (!is_array($fieldValues)) {
if (strlen($fieldValues) > 0) {
$fieldValues = array($fieldValues);
} else {
return;
}
}
foreach ($fieldValues as $fieldValue) {
$valuePattern = '/value=['"]?Q' . $fieldValue . 'E['"]+/i';
for ($cnt = 0; $cnt < $numMatches; $cnt++) {
$htmlTag = $matches[1][$cnt];
if ( preg_match($valuePattern, $htmlTag) ) {
break;
}
}
$checkedPattern = '/([s]*)([/]?)>$/i';
$replacementPattern = ' checked="checked"12>';
$htmlTagToCheck = preg_replace($checkedPattern, $replacementPattern, $htmlTag);
$codeHtmlForm = str_replace($htmlTag, $htmlTagToCheck, $codeHtmlForm);
}
}
function ProcessPHPFile($PHPFile) {
ob_start();
if (file_exists($PHPFile)) {
require $PHPFile;
} else {
echo '<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><title>Error</title></head><body>Forms To Go - Error: Unable to load HTML form: ' . $PHPFile . '</body></html>';
exit;
}
return ob_get_clean();
}
function CheckString($value, $low, $high, $mode, $limitAlpha, $limitNumbers, $limitEmptySpaces, $limitExtraChars, $optional) {
$regEx = '';
if ($limitAlpha == kYes) {
$regExp = 'A-Za-z';
}
if ($limitNumbers == kYes) {
$regExp .= '0-9';
}
if ($limitEmptySpaces == kYes) {
$regExp .= ' ';
}
if (strlen($limitExtraChars) > 0) {
$search = array('', '[', ']', '-', '$', '.', '*', '(', ')', '?', '+', '^', '{', '}', '|', '/');
$replace = array('', '[', ']', '-', '$', '.', '*', '(', ')', '?', '+', '^', '{', '}', '|', '/');
$regExp .= str_replace($search, $replace, $limitExtraChars);
}
if ( (strlen($regExp) > 0) && (strlen($value) > 0) ){
if (preg_match('/[^' . $regExp . ']/', $value)) {
return false;
}
}
if ( (strlen($value) == 0) && ($optional === kOptional) ) {
return true;
} elseif ( (strlen($value) >= $low) && ($mode == kStringRangeFrom) ) {
return true;
} elseif ( (strlen($value) <= $high) && ($mode == kStringRangeTo) ) {
return true;
} elseif ( (strlen($value) >= $low) && (strlen($value) <= $high) && ($mode == kStringRangeBetween) ) {
return true;
} else {
return false;
}
}
function CheckEmail($email, $optional) {
if ( (strlen($email) == 0) && ($optional === kOptional) ) {
return true;
} elseif ( preg_match("/^([w!#$%&'*+-/=?^`{|}~]+.)*[w!#$%&'*+-/=?^`{|}~]+@((((([a-z0-9]{1}[a-z0-9-]{0,62}[a-z0-9]{1})|[a-z]).)+[a-z]{2,6})|(d{1,3}.){3}d{1,3}(:d{1,5})?)$/i", $email) == 1 ) {
return true;
} else {
return false;
}
}
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$clientIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$clientIP = $_SERVER['REMOTE_ADDR'];
}
$FTGContactName = DoStripSlashes( $_POST['ContactName'] );
$FTGContactEmail = DoStripSlashes( $_POST['ContactEmail'] );
$FTGContactPhone = DoStripSlashes( $_POST['ContactPhone'] );
$FTGContactInterest = DoStripSlashes( $_POST['ContactInterest'] );
$FTGContactComments = DoStripSlashes( $_POST['ContactComments'] );
$FTGContactSubmit = DoStripSlashes( $_POST['ContactSubmit'] );
$List_ContactInterest = ListArray($FTGContactInterest);
$validationFailed = false;
# Fields Validations
if (!CheckString($FTGContactName, 1, 0, kStringRangeFrom, kNo, kNo, kNo, '', kMandatory)) {
$FTGErrorMessage['ContactName'] = 'Enter Your Name';
$validationFailed = true;
}
if (!CheckEmail($FTGContactEmail, kMandatory)) {
$FTGErrorMessage['ContactEmail'] = 'Enter Valid Email Address';
$validationFailed = true;
}
if (!CheckString($FTGContactPhone, 1, 0, kStringRangeFrom, kNo, kNo, kNo, '', kMandatory)) {
$FTGErrorMessage['ContactPhone'] = 'Enter Your Phone Number';
$validationFailed = true;
}
if (!CheckString($List_ContactInterest, 1, 0, kStringRangeFrom, kNo, kNo, kNo, '', kMandatory)) {
$FTGErrorMessage['ContactInterest'] = 'Select Your Interest';
$validationFailed = true;
}
# Display HTML form with filled values
if ($validationFailed === true) {
$fileHtmlForm = '/vservers/example/htdocs/contact.php';
$codeHtmlForm = ProcessPHPFile($fileHtmlForm);
ProcessTextField($codeHtmlForm, 'ContactName', $FTGContactName);
ProcessTextField($codeHtmlForm, 'ContactEmail', $FTGContactEmail);
ProcessTextField($codeHtmlForm, 'ContactPhone', $FTGContactPhone);
ProcessCheckBoxes($codeHtmlForm, 'ContactInterest', $FTGContactInterest);
ProcessTextArea($codeHtmlForm, 'ContactComments', $FTGContactComments);
$errorList = @implode("<br />n", $FTGErrorMessage);
$codeHtmlForm = str_replace('<!--VALIDATIONERROR-->', $errorList, $codeHtmlForm);
$codeHtmlForm = str_replace('<!--FIELDVALUE:ContactName-->', $FTGContactName, $codeHtmlForm);
$codeHtmlForm = str_replace('<!--FIELDVALUE:ContactEmail-->', $FTGContactEmail, $codeHtmlForm);
$codeHtmlForm = str_replace('<!--FIELDVALUE:ContactPhone-->', $FTGContactPhone, $codeHtmlForm);
$codeHtmlForm = str_replace('<!--FIELDVALUE:ContactInterest-->', $List_ContactInterest, $codeHtmlForm);
$codeHtmlForm = str_replace('<!--FIELDVALUE:ContactComments-->', $FTGContactComments, $codeHtmlForm);
$codeHtmlForm = str_replace('<!--FIELDVALUE:ContactSubmit-->', $FTGContactSubmit, $codeHtmlForm);
$codeHtmlForm = str_replace('<!--ERRORMSG:ContactName-->', $FTGErrorMessage['ContactName'], $codeHtmlForm);
$codeHtmlForm = str_replace('<!--ERRORMSG:ContactEmail-->', $FTGErrorMessage['ContactEmail'], $codeHtmlForm);
$codeHtmlForm = str_replace('<!--ERRORMSG:ContactPhone-->', $FTGErrorMessage['ContactPhone'], $codeHtmlForm);
$codeHtmlForm = str_replace('<!--ERRORMSG:ContactInterest-->', $FTGErrorMessage['ContactInterest'], $codeHtmlForm);
if (count( array_filter( $FTGErrorMessage ) ) > 0 ) {
foreach( $FTGErrorMessage as $key => $message ) {
$ErrorMessage .= trim( str_replace("'", "'", $message ) ) . 'n';
}
$alertJSErrorMessage = "window.alert('" . $ErrorMessage . "');";
$onloadPattern = '/(<body[^>]+onload=["]*)"([^>]*)>/i';
if ( preg_match( $onloadPattern, $codeHtmlForm ) ) {
$replacementPattern = '1"' . $alertJSErrorMessage . '2>';
} else {
$onloadPattern = '/(<body[^>]*)>/i';
$replacementPattern = '1 onload="' . $alertJSErrorMessage . '">';
}
$codeHtmlForm = preg_replace( $onloadPattern, $replacementPattern, $codeHtmlForm);
}
echo $codeHtmlForm;
}
if ( $validationFailed === false ) {
# Email to Form Owner
$emailSubject = FilterCChars("Inquiry From Contact Page");
$emailBody = "You have received an inquiry on your Contact page. Below is the information given:n"
. "n"
. "n"
. "Name : $FTGContactNamen"
. "n"
. "Phone : $FTGContactPhonen"
. "Email : $FTGContactEmailn"
. "n"
. "n"
. "Interested In : $List_ContactInterestn"
. "n"
. "Comments : n"
. "n"
. "$FTGContactCommentsn"
. "";
$emailTo = 'Christian Balmer <email@hidden>';
$emailFrom = FilterCChars("email@hidden");
$emailHeader = "From: $emailFromn"
. "MIME-Version: 1.0n"
. "Content-type: text/plain; charset="UTF-8"n"
. "Content-transfer-encoding: 8bitn";
mail($emailTo, $emailSubject, $emailBody, $emailHeader);
# Confirmation Email to User
$confEmailTo = FilterCChars($FTGContactEmail);
$confEmailSubject = FilterCChars("Thank You For Your Inquiry");
$confEmailBody = "Hi #Name#,n"
. "n"
. "Thank you for your inquiry in Xtremity Beauty Supply. We have received your information and someone will respond shortly.n"
. "n"
. "n"
. "Sincerly,n"
. "n"
. "Xtremity Beauty Supply";
$confEmailHeader = "From: email@hidden"
. "MIME-Version: 1.0n"
. "Content-type: text/plain; charset="UTF-8"n"
. "Content-transfer-encoding: 8bitn";
mail($confEmailTo, $confEmailSubject, $confEmailBody, $confEmailHeader);
# Embed success page and dump it to the browser
$fileSuccessPage = '/vservers/example/htdocs/contact.php';
if (file_exists($fileSuccessPage) === false) {
echo '<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><title>Error</title></head><body>The success page: <b> ' . $fileSuccessPage . '</b> cannot be found on the server.</body></html>';
exit;
}
$successPage = ProcessPHPFile($fileSuccessPage);
$successPage = str_replace('<!--FIELDVALUE:ContactName-->', $FTGContactName, $successPage);
$successPage = str_replace('<!--FIELDVALUE:ContactEmail-->', $FTGContactEmail, $successPage);
$successPage = str_replace('<!--FIELDVALUE:ContactPhone-->', $FTGContactPhone, $successPage);
$successPage = str_replace('<!--FIELDVALUE:ContactInterest-->', $List_ContactInterest, $successPage);
$successPage = str_replace('<!--FIELDVALUE:ContactComments-->', $FTGContactComments, $successPage);
$successPage = str_replace('<!--FIELDVALUE:ContactSubmit-->', $FTGContactSubmit, $successPage);
echo $successPage;
}
?>
TeamSDA_Christian
freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options