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)

By gkornbluth - October 7, 2013


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 Daryl - October 9, 2013

Hi Jerry,

What I would do is I will capture the date_year value and date_month value and put them in a hidden field in the  $order_by request form.

<form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<input type="hidden" name="date_year" value="<?php echo @$_REQUEST['date_year']; ?>">
<input type="hidden" name="date_month" value="<?php echo @$_REQUEST['date_month']; ?>">
<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>

Hope this helps.

Cheers!

Daryl Maximo
PHP Programmer - interactivetools.com

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