Form problems

7 posts by 2 authors in: Forums > CMS Builder
Last Post: September 24, 2009   (RSS)

Re: [northernpenguin] Form problems

By Chris - September 23, 2009

Hi northernpenguin,

Your detail page probably has code like this at the top:

list($historyRecords_detail, $historyMetaData) = getRecords(array(
'tableName' => 'history',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));


That code will look for a record number in the URL (e.g. detail.php?title-123) and display that record. However, the way you're trying to select records is with the search features.

I think all that you need to do is remove this line from your detail page:

'where' => whereRecordNumberInUrl(1),

With no "where" specified, getRecords will construct its own search from the year submitted by the form.

I hope this helps! Please let me know if you have any questions.
All the best,
Chris

Re: [chris] Form problems

Hi Chris

I removed the 'where' as you suggested, but there was no difference in the results. Below is the code at the top of my historyDetails_e.php page:

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

list($history_detailsRecords, $history_detailsMetaData) = getRecords(array(
'tableName' => 'history_details',

'loadUploads' => '0',
'limit' => '1',
));
$history_detailsRecord = @$history_detailsRecords[0]; // get first record

// show error message if no matching record is found
if (!$history_detailsRecord) {
print "Record not found!";
exit;
}

?>


I'm still stumped!
--
northernpenguin
Northern Penguin Technologies

"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke

Re: [northernpenguin] Form problems

By Chris - September 23, 2009

Hi northernpenguin,

I had assumed that your history_details section had a "year" field, but I guess not. What fields do you have in the history_details section and how were you planning on looking up records based on the visitor's selection of a year?
All the best,
Chris

Re: [chris] Form problems

Chris: Actually, it does (its named 'title'). My table has the foll fields:

title --> List
content --> wysiwyg
content_fr --> wysiwyg

Maybe there is another way of doing this. I'm going to try something else and get back to you.
--
northernpenguin
Northern Penguin Technologies

"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke

Re: [northernpenguin] Form problems

By Chris - September 23, 2009

Hi northernpenguin,

You'll want to change your <select> from this:

<select name="year" size="1" style="width:100px;">

to this

<select name="title" size="1" style="width:100px;">

so that CMSB will know which field to search on.

I hope this helps! Please let me know if you have any more questions.
All the best,
Chris

Re: [chris] Form problems

Chis: that was definitely part of the problem. I re-wrote both files and included the following:

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

list($historyRecords, $historyMetaData) = getRecords(array(
'tableName' => 'history',
'loadUploads' => '0',
));


?>


and

<form name="yearsearch" action="historyDetails_e.php?year=" method="post">
Choose a year:
<select name="year" size="1" style="width: 160px;">
<?php foreach ($historyRecords as $record): ?>
<option value="<?php echo $record['title'] ?>"><?php echo $record['title'] ?></option>
<?php endforeach; ?>
</select>
<input type="submit" value="Submit">
</form>

<?php if (!$historyRecords): ?>
No records were found!<br/><br/>
<?php endif ?>


It now works! I also renamed the field "title" to "year" to simplify my life!

Thanx for your help Chris. Your original post where you mentioned searching gave me the hint i needed.

[:)]
--
northernpenguin
Northern Penguin Technologies

"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke