Negin Nickparsa
2014-10-23 17:10:33 UTC
I have items showing up in list view or grid view.
I have 2 buttons List and Grid
and Items will show up in Grid view and List view
also I order them in a select tag by price and other options
when I sort by name I want to remember the state of view
whether it is grid or if it is list
user selects Grid view and then wants to order them by price. but when they
order by price booom!(submitted) they will go to default view which was
List view.It is not correct so bad.
I have an event onchange that when I click on selection the form will be
submitted
I want to keep the values so that it can remember whether it should sort
the items in grid view or list view
the live example can be seen here:
http://www.lenmar.com/general-purpose/aa/aa/nickel-metal-hydride/nickel-metal-hydride-battery
this is the older version which is working with Get method but the test
server is with $_POST I am showing the concept to help clarifying the
problem
as far as I attempted, I got the hidden values for $_POST
and then I pass them to the form but it still has problem
here is the sample code:
<form method="post" action="" id="myform">
<div id="gridSort">
<input type="hidden" name="selected_sort" value="<?php echo
!empty($_POST['sort']) ? strip_tags($_POST['sort']) : ''; ?>" />
<input type="hidden" name="selectionList_view" value="<?php echo
!empty($_POST['Listview']) ? strip_tags($_POST['Listview']) : ''; ?>" />
<input type="hidden" name="selectionGrid_view" value="<?php echo
!empty($_POST['Gridview']) ? strip_tags($_POST['Gridview']) : ''; ?>" />
<span>View Results As:</span> <span>
<input type="submit" class="listButtons" name="Lisview" value="List">
</span> <span>
<input type="submit" class="resultButtons" name="Gridview"
value="Grid"></span>
<select id="sortSelect" class="sortSelect" size="1" name="sort"
onchange="this.form.submit();" >
<option selected>Sort</option>
<option value="Name">Name</option>
<option value="PriceLowToHigh">Price - Low</option>
<option value="PriceHighToLow">Price - High</option>
</select>
</div>
</form>
<script type="text/javascript">
document.getElementById('sortSelect').value ="<?php if(!
$_POST['sort']):?>"Sort"<?php else: echo $_POST['sort']; endif;?>";
</script>
<pre>
<?php print_r($_POST); ?>
</pre>
I select the price high to low or something else I want it to remember what
I had chosen before that list? or grid?
my question is that is it possible to have just 1 form and submit and keep
them? hidden field didn't work as I tested.
Any help would be appreciated.
Sincerely
Negin Nickparsa
I have 2 buttons List and Grid
and Items will show up in Grid view and List view
also I order them in a select tag by price and other options
when I sort by name I want to remember the state of view
whether it is grid or if it is list
user selects Grid view and then wants to order them by price. but when they
order by price booom!(submitted) they will go to default view which was
List view.It is not correct so bad.
I have an event onchange that when I click on selection the form will be
submitted
I want to keep the values so that it can remember whether it should sort
the items in grid view or list view
the live example can be seen here:
http://www.lenmar.com/general-purpose/aa/aa/nickel-metal-hydride/nickel-metal-hydride-battery
this is the older version which is working with Get method but the test
server is with $_POST I am showing the concept to help clarifying the
problem
as far as I attempted, I got the hidden values for $_POST
and then I pass them to the form but it still has problem
here is the sample code:
<form method="post" action="" id="myform">
<div id="gridSort">
<input type="hidden" name="selected_sort" value="<?php echo
!empty($_POST['sort']) ? strip_tags($_POST['sort']) : ''; ?>" />
<input type="hidden" name="selectionList_view" value="<?php echo
!empty($_POST['Listview']) ? strip_tags($_POST['Listview']) : ''; ?>" />
<input type="hidden" name="selectionGrid_view" value="<?php echo
!empty($_POST['Gridview']) ? strip_tags($_POST['Gridview']) : ''; ?>" />
<span>View Results As:</span> <span>
<input type="submit" class="listButtons" name="Lisview" value="List">
</span> <span>
<input type="submit" class="resultButtons" name="Gridview"
value="Grid"></span>
<select id="sortSelect" class="sortSelect" size="1" name="sort"
onchange="this.form.submit();" >
<option selected>Sort</option>
<option value="Name">Name</option>
<option value="PriceLowToHigh">Price - Low</option>
<option value="PriceHighToLow">Price - High</option>
</select>
</div>
</form>
<script type="text/javascript">
document.getElementById('sortSelect').value ="<?php if(!
$_POST['sort']):?>"Sort"<?php else: echo $_POST['sort']; endif;?>";
</script>
<pre>
<?php print_r($_POST); ?>
</pre>
I select the price high to low or something else I want it to remember what
I had chosen before that list? or grid?
my question is that is it possible to have just 1 form and submit and keep
them? hidden field didn't work as I tested.
Any help would be appreciated.
Sincerely
Negin Nickparsa