Prblems with addForm.php

9 posts by 3 authors in: Forums > CMS Builder
Last Post: July 6, 2010   (RSS)

By JeffC - July 6, 2010

I have downloaded the file addForm.php from this forum. I have got it to work perfectly as a standalone file using the code below. However. I run into problems when I call this form from another file using <?php require("addForm.php"); ?>

The form loads and displays correctly but when it is submitted instead of successfully submitting the form it says 'Record Not found'


This is the code of the file addForm.php. (Scroll down for the file promotion.php which is the file this file)

<?php
require_once "cmsAdmin/lib/viewer_functions.php";

// submit form
if (@$_REQUEST['submit']) {

// error checking
$errorsAndAlerts = "";
if (!@$_REQUEST['first_name']) { $errorsAndAlerts .= "Please enter your first name<br/>\n"; }
if (!@$_REQUEST['title']) { $errorsAndAlerts .= "Please enter your surname<br/>\n"; }
if (!@$_REQUEST['email']) { $errorsAndAlerts .= "Please enter your email address<br/>\n"; }
if (!@$_REQUEST['answer']) { $errorsAndAlerts .= "Please enter your answer<br/>\n"; }
if (!@$_REQUEST['type']) { $errorsAndAlerts .= "Please select your interest<br/>\n"; }

// turn off strict mysql error checking for: STRICT_ALL_TABLES
mysqlStrictMode(false); // disable Mysql strict errors for when a field isn't defined below (can be caused when fields are added later)

// add record
if (!@$errorsAndAlerts) {
mysql_query("INSERT INTO `{$TABLE_PREFIX}contacts` SET
title = '".mysql_real_escape_string( $_REQUEST['title'] )."',
first_name = '".mysql_real_escape_string( $_REQUEST['first_name'] )."',
email = '".mysql_real_escape_string( $_REQUEST['email'] )."',
answer = '".mysql_real_escape_string( $_REQUEST['answer'] )."',
type = '".mysql_real_escape_string( $_REQUEST['type'] )."',
newsletter_sign_up = '".(@$_REQUEST['newsletter_sign_up'] ? '1' : '0')."',

createdDate = NOW(),
updatedDate = NOW(),
createdByUserNum = '0',
updatedByUserNum = '0'")
or die("MySQL Error Creating Record:<br/>\n". htmlspecialchars(mysql_error()) . "\n");
$recordNum = mysql_insert_id();

// display thanks message and clear form
$errorsAndAlerts = "Thanks, we have received your entry";
$_REQUEST = array();
}

}

?>

<form method="post" action="">
<input type="hidden" name="submit" value="1" />


<?php if (@$errorsAndAlerts): ?>
<div style="color: red; font-size: 0.8em; font-weight: normal; padding-left: 10px;"><br/>
<?php echo $errorsAndAlerts; ?><br/><br/>
</div>
<?php endif ?>

<div style="font-weight: normal; font-size: 0.8em; line-height: 2.4em; padding-left: 10px;"><br/>
<table border="0" cellspacing="0" cellpadding="0">
<tr>

<td width="120" valign="top">First name</td>
<td><input type="text" name="first_name" value="<?php echo htmlspecialchars(@$_REQUEST['first_name']) ?>" size="30" /></td></td>
</tr>

<tr>
<td valign="top">Surname</td>
<td><input type="text" name="title" value="<?php echo htmlspecialchars(@$_REQUEST['title']) ?>" size="30" /></td>
</tr>

<tr>
<td valign="top">Email address</td>
<td><input type="text" name="email" value="<?php echo htmlspecialchars(@$_REQUEST['email']) ?>" size="30" /></td>
</tr>

<tr>
<td width="120" valign="top">Answer</td>
<td><input type="text" name="answer" value="<?php echo htmlspecialchars(@$_REQUEST['answer']) ?>" size="30" /></td>
</tr>
</table>
</div>

<div style="font-weight: normal; font-size: 0.8em; line-height: 1.6em; padding-left: 10px;"><br/>
<table>
<tr>
<td><select name="type"/>
<option selected="selected">Please select one</option>
<option value="I am a restaurant or pub/bar owner" <?php selectedIf(@$_REQUEST['I am a restaurant or pub/bar owner'], 'I am a restaurant or pub/bar owner') ?>>I am a restaurant or pub/bar owner</option>
<option value="I am a food or drink producer" <?php selectedIf(@$_REQUEST['I am a food or drink producer'], 'I am a food or drink producer') ?>>I am a food or drink producer</option>
<option value="I am a food or drink retailer" <?php selectedIf(@$_REQUEST['I am a food or drink retailer'], 'I am a food or drink retailer') ?>>I am a food or drink retailer</option>
<option value="None of the above &#8211; I am just interested in Devon&#8217;s food and drink" <?php selectedIf(@$_REQUEST['None of the above &#8211; I am just interested in Devon&#8217;s food and drink'], 'None of the above &#8211; I am just interested in Devon&#8217;s food and drink') ?>>None of the above &#8211; I am just interested in Devon&#8217;s food and drink</option>
</td>
</tr>
</table>
</div>

<div style="font-weight: normal; font-size: 0.8em; line-height: 1.6em; padding-left: 10px;"><br/>
<table>
<tr>
<td valign="top">
Sign up to the xxxxxxxxxxxxx newsletter to receive details of more competitions and food news directly in your inbox <input name="newsletter_sign_up" type="checkbox" value="1" <?php checkedIf(@$_REQUEST['newsletter_sign_up'], '1') ?>" />
</td>
</tr>
</table>
</div>

<div style="font-weight: normal; font-size: 0.8em; line-height: 1.6em; padding-left: 10px;"><br/>
<input type="submit" name="add" value="Submit your answer &gt;" />
</div>
</form>




This is the code for the file promotion.php from which addForm.php is called


<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
require_once "cmsAdmin/lib/viewer_functions.php";

list($promoRecords, $promoMetaData) = getRecords(array(
'tableName' => 'promo',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));

$promoRecord = @$promoRecords[0];

if (!$promoRecord) {
header("HTTP/1.0 404 Not Found");
print "Record not found!";
exit;


}


?><!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" xmlns:v="urn:schemas-microsoft-com:vml">

<head>
<title><?php echo $promoRecord['title'] ?>Promotion.</title>
<meta name="description" content="<?php echo $promoRecord['short_description'] ?>" />
<link href="/css/xxxxxxxxxxxxx.css" rel="stylesheet" type="text/css" />
<link href="/css/mainnavigation.css" rel="stylesheet" type="text/css" />
<script src="scripts/curvycorners.src.js" type="text/JavaScript"></script>
<script src="http://s7.addthis.com/js/250/addthis_widget.js" type="text/javascript"></script>
<link href="/css/highslide.css" rel="stylesheet" type="text/css" />

<script src="xxxxxxxxxxxxx/scripts/highslide-with-gallery.js" type="text/javascript"></script>
<script src="xxxxxxxxxxxxx/scripts/highslide.config.js" type="text/javascript"></script>
<!--[if lt IE 7]>
<link rel="stylesheet" type="text/css" href="../css/highslide-ie6.css" />
<![endif]-->
</head>


<body>

<?php include_once("analyticstracking.php") ?>

<div id="container">

<div id="headergraphic">
<img src="/images/xxxxxxxxxxxxx.gif" width="319" height="78" alt="xxxxxxxxxxxxx logo" />
</div><!-- end div id headergraphic -->


<ul id="menu">
<li><a href="xxxxxxxxxxxxx" title="">xxxxxxxxxxxxx</a></li>
<li><a href="xxxxxxxxxxxxx" title="">xxxxxxxxxxxxx</a></li>
<li><a href="/xxxxxxxxxxxxx" title="">xxxxxxxxxxxxx</a></li>
<li><a href="xxxxxxxxxxxxx" title="">xxxxxxxxxxxxx</a></li>
<li><a href="xxxxxxxxxxxxx" title="">xxxxxxxxxxxxx</a></li>
<li><a href="xxxxxxxxxxxxx" title="">xxxxxxxxxxxxx</a></li>
</ul>

<div id="background">




<div id="breadcrumb">
<a href="index.php">Home</a> / <a href="<?php echo $promoMetaData['_listPage']; ?>"> Promotion</a> / <?php echo $promoRecord['title'] ?>
</div><!-- end div id breadcrumb -->

<div id="maincontent">
<div id="editorial">

<h1><?php echo $promoRecord['title'] ?></h1>
<h2><?php echo $promoRecord['short_description'] ?></h2>


<div id="text">
<?php echo $promoRecord['content'] ?>
<p><?php if (!$promoRecord): ?> No record found!<?php endif ?></p>
</div><!-- end div id text -->

<div class="highslide-gallery">
<?php foreach ($promoRecord['image'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<a id="thumb1" href="<?php echo $upload['urlPath'] ?>" class="highslide" onclick="return hs.expand(this, config1 )">
<img src="<?php echo $upload['thumbUrlPath'] ?>" alt="<?php echo $upload['info1'] ?>" /></a>
<?php break; ?>
<?php endif ?>
<?php endforeach ?>

<div class="hidden-container">
<?php $counter = 1; ?>
<?php foreach ($promoRecord['image'] as $upload): ?>
<?php if ($upload['hasThumbnail'] && $counter > 1): ?>
<a id="thumb<?php echo $counter; ?>" href="<?php echo $upload['urlPath'] ?>" class="highslide" onclick="return hs.expand(this, config1 )">
<img src="<?php echo $upload['thumbUrlPath'] ?>" alt="<?php echo $upload['info1'] ?>" /></a>
<?php endif ?>
<?php $counter++; ?>
<?php endforeach ?>
</div>
</div>




<div id="contact">
<h4>How To Enter</h4>
<p><?php echo $promoRecord['how_to_enter'] ?></p>

<?php require("addForm.php"); ?>

</div><!-- end div id contact -->



</div> <!-- end div class editorial -->


<div id="pagefurntiture">
<div id="addthis_toolbox">
<hr/>
<p class="nobreak">Bookmark or share this page:</p>

<div class="custom_images">
<a class="addthis_button_twitter"><img src="/images/twitter_40x40.png" width="40" height="40" alt="Twitter" /></a>
<a class="addthis_button_facebook"><img src="/images/facebook_40x40.png" width="40" height="40" alt="Facebook" /></a>
<a class="addthis_button_reddit"><img src="/images/Reddit_40x40.png" width="40" height="40" alt="StumbleUpon" /></a>
<a class="addthis_button_stumbleupon"><img src="/images/Stumbleupon_40x40.png" width="40" height="40" alt="StumbleUpon" /></a>
<a class="addthis_button_delicious"><img src="/images/delicious_40x40.png" width="40" height="40" alt="Delicious" /></a>
<a class="addthis_button_digg"><img src="/images/digg-logo_40x47.png" width="47" height="40" alt="Digg" /></a>
<p class="nobreak">Don't know what these symbols mean? <a href="/social_bookmarking_explained.php">Social bookmarking explained.</a></p>
</div><!-- end div id custom images -->

<hr/>

<p class="footnote">xxxxxxxxxxxxxcontains editorial content from external contributors, which do not necessarily reflect the views of its publisher or editor. Please call the venue for confirmation of opening times, etc.</p>
</div><!-- end div id add this tool box -->

</div>


<br class="clearfloat" />
</div><!-- end div id maincontent -->

<div id="subscription">
<?php require("subscription.php"); ?>
</div><!-- end div id subscription -->

<br class="clearfloat" />
</div> <!-- end div id background -->

<div id="footer">
&copy; xxxxxxxxxxxxx" title="xxxxxxxxxxxxx">jxxxxxxxxxxxxx </a>
</div>

</div><!-- end div id container -->

</body>
</html>


Jeff

Re: [Jeffncou] Prblems with addForm.php

By Jason - July 6, 2010

Hi,

The problem is in promotion.php. What's happening is that at the very beginning of the file, you're using this code to select your promo records:

list($promoRecords, $promoMetaData) = getRecords(array(
'tableName' => 'promo',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));

$promoRecord = @$promoRecords[0];

if (!$promoRecord) {
header("HTTP/1.0 404 Not Found");
print "Record not found!";
exit;


This uses the record number from the url to select a record. Once you submit the form, however, it changes the query string and the code is pulling a number from the string that is not a record number.

Could you tell me what is stored in the "promo" table? Is it a single record? Why do you only want the one record? If you could let me know what that table is used for, I can help you come up with a solution.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Prblems with addForm.php

By JeffC - July 6, 2010

Hi Jason

Thanks for the reply

The promo table could contain more than one record. It is used for competitions. There is a chance that two or more competitions may run simultaneously hence setting it up as a multi-record.

the addForm.php populates a separate table called contacts.

I use this table to collect newsletter sign ups and it also has contact details for all my clients.

I have set up a field in the contacts table called 'answer'. My idea was that someone can enter the competition by filling out the form. Their answer gets submitted to the 'answer' field. I can then export all of the correct entries using the csv export plug in.

If I have multiple competitions running at the same time I have all of the competition entries in one place.

If they choose to check the 'sign me up for a newsletter' I also have the details automatically with all of the other newsletter sign ups that have come from other sources.

Basically I have set it up this way so that I have all of my contacts in one place giving me the most flexibility when exporting the data to use with marketing campaigns

Thanks
Jeff

Re: [Jason] Prblems with addForm.php

By JeffC - July 6, 2010

Hi Jason

Unfortunately that hasn't resolved the problem

Instead of going to
http://www.xxxxxx.co.uk/promotion/WIN-1

it goes to
http://www.xxxxxx.co.uk/promotion/WIN-1/?num=1
Jeff

Re: [Jeffncou] Prblems with addForm.php

By Jason - July 6, 2010

Hi,

Okay. If you could email your CMS Builder and FTP Login details to jason@interactivetools.com, I can look into this further.

Please only email this information, don't post it to the forum.

Thanks.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Prblems with addForm.php

By JeffC - July 6, 2010

Thank you

I have emailed the details
Jeff

Re: [Jeffncou] Prblems with addForm.php

By Jason - July 6, 2010

Hi,


I took a look at the problem. What was actually happening was when the form was being submitted, CMS Builder was adding the values from the form to the where clause. This was why it wasn't returning any records. To get around this, I added 'allowSearch' => false, to where we're getting the records.

I also took out the code we had added earlier.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jeffncou] Prblems with addForm.php

By gkornbluth - July 6, 2010

Hi jeffncou,

Interesting implementation.

Could you attach the working code so we can learn from it?

Just curious.

Have you implemented a double opt in for your newsletter signup?

best,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php