Form Problem
2 posts by 2 authors in: Forums > CMS Builder
Last Post: June 4, 2012 (RSS)
By Perchpole - June 1, 2012 - edited: June 1, 2012
I'm having a problem with form I originaly began using as a result of this post:
http://www.interactivetools.com/iforum/Products_C2/CMS_Builder_F35/gforum.cgi?post=92670
I added a new drop-down menu to the form which is populated by results returned by a get records call (both in red below):
The form works - except in one important regard:
When a user neglects to enter any text (in the "Text" box), an error message is triggered and the form is reloaded.
However, when someone fails to enter a "Title", we get the error message and the form is reloaded - but without the contents of the drop-down menu. It's as if the the getRecords() call has stopped working.
I can't understand what's going on.
:0/
Perch
http://www.interactivetools.com/iforum/Products_C2/CMS_Builder_F35/gforum.cgi?post=92670
I added a new drop-down menu to the form which is populated by results returned by a get records call (both in red below):
<?php
$libraryPath = 'cms/lib/viewer_functions.php';
$dirsToCheck = array('../path');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
// load themes
list($themeRecords) = getRecords(array(
'tableName' => 'theme',
));
// submit form
if (@$_REQUEST['submitForm']) {
// error checking
$errorsAndAlerts = "";
if (!@$_REQUEST['title']) { $errorsAndAlerts .= "Please specify title!<br/>\n"; }
if (!@$_REQUEST['text']) { $errorsAndAlerts .= "Please specify text!<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) {
$query = "INSERT INTO `{$TABLE_PREFIX}spare` SET
title = '".mysql_escape( $_REQUEST['title'] )."',
text = '".mysql_escape( $_REQUEST['text'] )."',
theme = '".mysql_escape( $_REQUEST['theme'] )."',
hidden = '0',
createdDate = NOW(),
updatedDate = NOW(),
createdByUserNum = '0',
updatedByUserNum = '0'";
mysql_query($query) 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've added that record!";
$_REQUEST = array();
}
}
?>
<!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></title>
<style type="text/css">
body, td { font-family: arial }
</style>
</head>
<body>
<form method="post" action="">
<input type="hidden" name="submitForm" value="1" />
<h1>Sample Record Add Form</h1>
<?php if (@$errorsAndAlerts): ?>
<div style="color: red; font-weight: bold; font-size: 16px;"><br/>
<?php echo $errorsAndAlerts; ?><br/><br/>
</div>
<?php endif ?>
<table border="0" cellspacing="0" cellpadding="2">
<tr>
<td valign="top">Title</td>
<td><input class="text-input medium-input" type="text" name="title" value="<?php echo htmlspecialchars(@$_REQUEST['title']) ?>" size="30" /></td>
</tr>
<tr>
<td valign="top">Text</td>
<td><textarea name="text" cols="30" rows="4"><?php echo htmlspecialchars(@$_REQUEST['text']) ?></textarea></td>
</tr>
<tr>
<td valign="top">Theme</td>
<td>
<select name="theme">
<?php foreach ($themeRecords as $theme): ?>
<option value="<?php echo $theme['num'] ?>"><?php echo $theme['title'] ?></option>
<?php endforeach ?>
</select>
</td>
</tr>
</table><br/><br/>
<input class="button" type="submit" name="add" value="Add Record >>" />
</form>
</body >
</html>
The form works - except in one important regard:
When a user neglects to enter any text (in the "Text" box), an error message is triggered and the form is reloaded.
However, when someone fails to enter a "Title", we get the error message and the form is reloaded - but without the contents of the drop-down menu. It's as if the the getRecords() call has stopped working.
I can't understand what's going on.
:0/
Perch
Re: [Perchpole] Form Problem
By Jason - June 4, 2012
Hi,
What's happening is that because "title" is a field name inside "theme", when the form is submitted, getRecords() is triggering an automatic search, which is returning no results.
Try this:
Hope this helps
What's happening is that because "title" is a field name inside "theme", when the form is submitted, getRecords() is triggering an automatic search, which is returning no results.
Try this:
// load themes
list($themeRecords) = getRecords(array(
'tableName' => 'theme',
'allowSearch'] => false,
));
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/
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/