Retaining values passed at end of URL after form submission

4 posts by 2 authors in: Forums > CMS Builder
Last Post: October 9, 2013   (RSS)


Hi All,

To facilitate accessing archives on  a blog that I’ve created I’m using the following to pass Values to my archive list page (blog3.php):

<?php
// get list of unique months and years with articles
$query = "SELECT DATE_FORMAT(date, '%M %Y') as dateAndYear, YEAR(date) as year, MONTH(date) as month FROM cms_blog GROUP BY dateAndYear ORDER BY date";
$result = mysql_query($query) or die("MySQL Error: ". htmlspecialchars(mysql_error()) . "\n");
while ($record = mysql_fetch_assoc($result)):
?>
 <a href="blog3.php?date_year=<?php echo $record['year'] ?>&date_month=<?php echo $record['month'] ?>"><?php echo $record['dateAndYear']; ?></a>

I’m also allowing visitors to the main blog page to choose whether they want to view posts by ascending or descending dates with this code:


<form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">
  <select name="order">
<option value="b">earliest date at the top</option>
<option value="a">most recent date at the top</option>
</select>
<input type="submit" name="submit" value="Click/Tap To Choose Display Order">
</form>
<?php $orderBy = "date";
if (@$FORM['order'] == 'b') { $orderBy = "date"; }
if (@$FORM['order'] == 'a') { $orderBy = "date DESC"; }

?>

<br>
<?php // load records from 'blog'
  list($blogRecords, $blogMetaData) = getRecords(array(
'tableName'   => 'blog',
'loadUploads' => true,
'allowSearch' => false,
    'orderBy' => $orderBy,
    
  ));
 
  ?>


The problem is, when I try to use the same approach on the archive page (blog3.php), submitting the  $order_by request form causes the date_year and date_month data to disappears from the end of the URL, resulting in errors.

How can I retain the data at the end of the URL after submitting the $order_by request on the archive page.

Thanks,

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

By gkornbluth - October 9, 2013 - edited: October 9, 2013

Hi Daryl,

Thanks for the insight. I'll give it a try in the morning.

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

Well I couldn't wait and I gave it a try.

Worked like a charm

Thank you Daryl.

The code on blog 3 is now

<span class="heading_font">Have It Your Way</span><br />
<form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">

  <select name="order">
    <option value="b">earliest date at the top</option>
    <option value="a">most recent date at the top</option>
  </select>
  <input type="submit" name="submit" value="Click/Tap To Choose Display Order">
</form>
<?php $orderBy = "date";
if (@$FORM['order'] == 'b') { $orderBy = "date"; }
if (@$FORM['order'] == 'a') { $orderBy = "date DESC"; }

?>
<?php $record_limit = $common_informationRecord['record_limit'] ?>
<?php if (@!$record_limit ) { $record_limit1 = ""; } ?>
<?php if (@$record_limit >=1 ) { $record_limit1 = $common_informationRecord['record_limit']; } ?>
<br>
<?php // load records from 'blog'
  list($blogRecords, $blogMetaData) = getRecords(array(
    'tableName'   => 'blog',
    'loadUploads' => true,
    'allowSearch' => false,
    'orderBy' => $orderBy,
    'limit' => $record_limit1,
  ));
 
  ?>

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