Form problems

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

Hi!

I'm having a bit of a problem with what I thought would be a simple issue. Basically I have a table, 'history_details' which contains the records I want to display. I have to php files, history_e.php and historyDetails_e.php.

In the history_e.php file, the user selects the specific year ('title') they want to see the detailed history by using a dropdown, single value.

<form method="post" action="historyDetails_e.php" >
<input type="hidden" name="submit" value="1" />
Choose a year: <br />
<select name="year" size="1" style="width:100px;">
<?php foreach ($history_detailsRecords as $record): ?>
<option value="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></option>
<?php endforeach; ?>
</select>
<?php if (!$history_detailsRecords): ?>
No records were found!<br/><br/>
<?php endif ?>

<input type="submit" value="submit" name="submit">
</form>


For some reason, no matter which year I select, only the first record is displayed on the historyDetails_e.php file. Below is the historyDetails_e.php code:

<center><h1><?php echo $history_detailsRecord['title'] ?></h1></center>

<?php echo $history_detailsRecord['content'] ?>
<?php if (!$history_detailsRecord): ?>
No record found!<br/><br/>
<?php endif ?>
<br />
<a href="<?php echo $history_detailsMetaData['_listPage']; ?>">&lt;&lt; Back to list page</a>


It looks like the select is not working properly. I obviously did something wrong in the code, but I'm note sure what!

http://www.51aircadets.ca/history_e.php
--
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,

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