Sincerely Negin Nickparsa On Thu, Oct 23, 2014 at 11:01 AM, Jeffry Killen <jekillen@xxxxxxxxxxx> wrote: > > On Oct 23, 2014, at 10:10 AM, Negin Nickparsa wrote: > > 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. >> > > How does the user designate the view he wants to see? > It appears that there must be a way, via javascript ajax call* > , to tell the server > initially what the preferred view is, so when the page reloads the correct > view > is displayed. > > *or get/post sent to the page that is being viewed. I would do this as > <?php > // in the top of the page being viewed. > > $_file_self = basename($_SERVER['PHP_SELF']); > $_view = ''; > if($_GET['view']) > { > $_view = $_GET['view']; > } > ?> > > The > > <a href="<?php print $_file_self ?>?view=grid">Grid View</a> > <a href="<?php print $_file_self ?>?view=list">List View</a> > > You may also want to save the view preference as a session variable > or have code write a preference file for the user. > Is the user required to have an account? If so, include a variable that > designates the default view preference. > > using get method can be a way to achieve it however I prefer to use post > method. > can you give me hints about ajax parts? maybe I can do something with that. for session they are so strict not using session for the sake of speed and security. > > > > >> 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 >> > >