I’m hoping this is a simple fix for someone better versed in customizing Magento…
I have a custom search form (on home.phtml) and results page (cms loading customresults.phtml) which returns a filtered collection of products, based on POST data entered in the form.
The process:
Form > POST values > multiple calculations based on POST > MySQL (core_read) query based on calculation results > product ID array (referred to below as $wow) based on query
Then:
$collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*')->addAttributeToFilter('entity_id', array('in'=>$wow))
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection)
$magento_block = Mage::getSingleton('core/layout');
$productsHtml = $magento_block->createBlock('catalog/product_list');
$productsHtml ->setTemplate('catalog/product/list.phtml')->setCollection($collection);
echo $productsHtml ->toHTML();
Results page loads nicely with the correct products showing. Toolbar loads and looks normal.
THE PROBLEM: on changing any setting in the toolbar on the results page, the page reloads and we’re left with no search results.
I assume the reload is killing the POST values…
Is there a way to (A) circumvent the page reload for toolbar functionality? Or alternatively, is it possible to somehow (B) retain the posted data or (C) force data re-submission on reload?
Any tips would be sincerely appreciated.
Solved the problem by using GET method instead of POST.
Not the solution I wanted, but it’s an easy workaround.
Just in case anyone else out there is having a similar issue.
Related
I am working on multiple one field forms to display in the footer of a clients website. Each time the page refreshes (like an adroator) a different question should be displayed. My clients CMS is wordpress so I'm using Ninjaform to create forms.
I have created multiple ninjaforms and tried to implement their shortcode and/or their php and neither will display properly, it just displays the code.
Seems like it is some conflict but not quite sure. Would like to find a simpler solution if there is one.
Thanks in advance.
In order to get the result of a shortcode, you need to "execute" it, which the ad rotator is probably not doing.
If you can insert text into the adrotator using PHP, you can execute the shortcode and get the results with:
$result = do_shortcode('[shortcode...]');
You can then insert the result.
I've started using FatFreeFramework for my current project and I've stumbled upon something I cannot seem to overcome.
In my application the user opens up a dialog through which he can insert a new category in to the system. He must also choose the two parent categories (second on should be dependent on the choice in the first one) and insert a title.(on the image below)
The problems are the populating of select fields and the submitting. How can I populate the select fields? How can I get the category to be added to the database without refreshing the page in any way? I know I should use ajax for this task, but I was unable to get anything to work due to (in my opinion) scarce documentation on this specific task.
How can I execute the ajax calls? I know the routes can have an [ajax] attribute but how does it work? How can it be incorporated?
Thank you for your help.
I have created a system using php from which we can add Status messages or you can say a kind of Microblog. So it has a database table like below :
posts_mst
------------------
post_id_pk
post_title
post_content
date_added
Now I have displayed all these posts on a page using select Query and it is displaying all the posts on a single page nicely. But now I have extended the page functionality and added a form to add these posts from same page. So that form stands on the very top of the page, and below it all the posts are getting listed.
I am storing all the posts using jquery .ajax() method so page do not load while saving any post. So now what I want to do is, when I add any posts, it should keep adding the same posts on the list in a real time, like you see in a Facebook - when someone posts on their wall, we see it loaded on the spot on our News feed. Here I want to do the same, as this page will be used by so may people and posts are displayed to everyone.
There is one way I can do this is - I can append a Div tag to the list of posts everytime a New post is added. This Div content I can get using Ajax response. But that will work for only My added post. If someone else adds the Post, I will not be knowing that.
So can anyone suggest me how I can implement this ? If there is any specific plugin used for that then let me know. :)
Thank you
The easiest way is to use a javascript setTimeout every X minutes / seconds and use ajax in the timeout function to check for new posts. You can track of what's new by storing a timestamp of the latest update in a session for example.
Note that this is periodic polling, it is not really realtime.
There are newer ways to maintain a permanent connection to the server, but that's a whole other story.
Hi i am facing a issue with the pagination helper. I am sorting the records based on user criteria like date range etc via drop downs . And it works fine. It paginates properly. But when i click on page 2, it shows page 2 of all results an not the sorted results. How can i fix it. The fields are sorted via POST and not GET and don't want it to be GET
You can try to store the post in the session, and then to fetch it when the page is loaded.
i.e.
if(isset($this->data)){
if(isset($this->data['clear'])){ //some field (button) which will clear the session
$this->Session->delete('post');
unset($this->data);
}
$this->Session->write('post', $this->data);
}
if($this->Session->read('post')){
$this->data = $this->Session->read('post');
}
If you want take a look on this component: Filter component. The post is a little bit old, but the component is adequate still and I am using it in my projects :)
It's hard to reverse engineering your source from a screenshot but i think the main problem is you're using POST therefore when user clicks to '2' you need to use some javascript to mimick a POST request.
I am not sure the correct terminology for the process that I am trying to describe. I don't even know which platform is underlying the technique. If you understand my description, please give the link to the site(s) and or the keyword name of the process. I think it is done by AJAX, but I am not certain. I use php as the backend code, I just need to find a way to dynamically display the results. Please give suggestions. I forgot the name of the sites that use this, and my link history expired.
TIA
Description:
The page would have a search form and options. After the user submits, the search is initiated, and the results appear inside the dedicated result area. The page does not refresh, just the info inside the result area.
The display area will show 20 (or whatever) results (lines). There will be next, and previous buttons. If you hit next, the next set of results will display.
I am writing a code that generates 20 results for each display. There is no set number of results, so the results might have a start/first page, but do not have an end page.
Each time the user hits 'next', the program would generate/load new results. It would also store previous results, so that when a user hits 'prev', the previous results can instantly come up.
What techniques/program are theses?
Having recently handled pagination with Code Igniter (php framework), the following links might help you and anyone else out:
http://tympanus.net/jPaginate/
http://codeigniter.com/forums/viewthread/93045/
Usability is important and AJAX pagination introduces some important questions that need addressing regarding pagination, the following article will give some usability guidelines for displaying results in a table:
http://thedesignvanguard.com/crud-r-for-read
Code Igniter Prototype Framework Ajax Pagination:
http://codeigniter.com/wiki/AJAX_Pagination_with_CI_Pagination_Library/
Since we're using jQuery, we chose the following, Codeigniter jQuery framework for AJAX pagination
http://tohin.wordpress.com/2008/08/12/codeigniter-ajax-pagination/
http://tohin.wordpress.com/2008/10/07/codeigniter-ajax-pagination-exampleguideline/
It is not AJAX for sure.
Nobody uses AJAX for the pagination.
And there are about zillion pagination examples over internet
The only thing is never described in articles is how to persist search options for the other pages.
But it's simple enough: http_build_query() can help you
You need to have a GET/POST form submitted via AJAX which contains the fields in the search term and page number.
If you are going to set the page size to 20 results, page_num=4 will show results from 61-80 results.
Usually search results are GET instead of POST (Ex: See Google search results ) along with the page_number as another attribute and value.
#IVAN .. good to know that the library came helpful..
About that searching option; check the recent commit in github
http://github.com/neotohin/CodeIgniter-Ajax-pagination-Library there is an additional parameter added for searching.
I think the simple code in readme is enough for understanding the mechanism.
You could use datatables
https://datatables.net/
https://datatables.net/examples/data_sources/server_side.html
With this plugin using jquery also you could use server sided page request , you just have to handle the plugin post using Ajax.
post automatically sends row , page offset column, search criteria you just have to provide the json encode return
and the plugin automatically has library in featuring pagination, search sort number of rows per page and the table formatting.
Needed are jquery, and the plugin css and js for this to work
let me know if you understood my explanation.
thanks (=