Multiple Forms on one web page

7 posts by 2 authors in: Forums > CMS Builder
Last Post: July 12, 2016   (RSS)

Hi

I have created a web page that has two (for now) forms, each connected to different multi-record table.  The problem is, no matter what I do, the second form always displays the top record and nothing else.

This is the top code:

<?php include 'common/includes/php_header.inc'; ?>
<?php
  // load record from 'history_overview'
  list($history_overviewRecords, $history_overviewMetaData) = getRecords(array(
    'tableName'   => 'history_overview',
    'where'       => '', // load first record
    'loadUploads' => true,
    'allowSearch' => false,
    'limit'       => '1',
  ));
  $history_overviewRecord = @$history_overviewRecords[0]; // get first record
  if (!$history_overviewRecord) { dieWith404("Record not found!"); } // show error message if no record found


  // load list records from 'historical_notes'
  list($historical_notesRecords, $historical_notesMetaData) = getRecords(array(
    'tableName'   => 'historical_notes',
    'loadUploads' => true,
    'allowSearch' => false,
  ));

  // load records from 'awards_trophies'
  list($awards_trophiesRecords, $awards_trophiesMetaData) = getRecords(array(
    'tableName'   => 'awards_trophies',
    'loadUploads' => true,
    'allowSearch' => false,
  ));
?>

These are the 2 forms:

<table>
<tr>
<td>
  <form method="get" action="historyNotes.php?">
  <h2>Select a year in history:</h2>
    <select name="year">
      <option value="">--</option>
      <?php foreach ($historical_notesRecords as $listRecord): ?>
        <option value="<?php echo htmlencode($listRecord['num']); ?>" <?php selectedIf($listRecord['num'], @$_REQUEST['year']); ?>>
          <?php echo htmlencode($listRecord['title']); ?>
        </option>
      <?php endforeach; ?>
    </select>
    <br>
    <input type="submit" value="Submit">
    </form>
</td>
<td>
<form method="get" action="historyAwards.php?">
  <h2>Select an award:</h2>
    <select name="title">
      <option value="">--</option>
      <?php foreach ($awards_trophiesRecords as $awardRecord): ?>
        <option value="<?php echo htmlencode($awardRecord['num']); ?>" <?php selectedIf($awardRecord['num'], @$_REQUEST['award']); ?>>
          <?php echo htmlencode($awardRecord['title']); ?>
        </option>
      <?php endforeach; ?>
    </select>
    <br>
    <input type="submit" value="Submit">
</form>
</td>
</tr>

</table>

Any ideas would be greatly appreciated!

Ragi

--
northernpenguin
Northern Penguin Technologies

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

Daryl:  Actually, what happens is the the first dropdown, "Select a year in history" selects a record from $historical_notesRecord.  That works perfectly, no issues.  The second dropdown, "Select an award" selects a record from $awards_trophiesRecords.  But no matter what I do, it only displays the 1st record.  

You can try it on my sandbox at http://742sandbox.northernpenguin.com/history.php

Ragi

--
northernpenguin
Northern Penguin Technologies

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

By Daryl - July 12, 2016

Ah, I see. When you select an award and click submit, it only displays the first record on the next page regardless of the award that you've selected.

Can you post your getRecords code from historyAwards.php file?

Have you tried 'where' => @$_REQUEST['award'], getRecords parameter?

Daryl Maximo
PHP Programmer - interactivetools.com

By northernpenguin - July 12, 2016 - edited: July 12, 2016

Daryl:  No, I haven't tried the 'where'.  Just tried it.  No difference.

Attached are all 3 files.

Ragi

--
northernpenguin
Northern Penguin Technologies

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

By Daryl - July 12, 2016

Can you try replacing the line 17 of historyAwards.php to:

'where'       => "num = '".mysql_escape(@$_REQUEST['title'])."'",

Please let me know if that works.

Thanks!

Daryl Maximo
PHP Programmer - interactivetools.com

Daryl:  you're a genius!

It worked.  Thank you.

Ragi

--
northernpenguin
Northern Penguin Technologies

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