Jump to content

Federico

Members
  • Posts

    106
  • Joined

  • Last visited

Everything posted by Federico

  1. Thank you Macrura, by inserting the php variable inside the action brackets did the trick. So here's the bottom line, for those that might experience the same issue: <form name='search' id='yourID' method='get' role='form' action="<?=$pages->get("template=YOURTEMPLATE")->url?>"> .....form values.... </form> Thank you! regards
  2. Since the search form has to bring search results in the same page, the form action is simply action="" If I insert anything else, the form will redirect to other page (es search.php) which does not serve this case. Other options have been tested but no luck..
  3. These are the passages that lead to the issue: __.com/en/works/ this is the page that host all paginated items. So you can go back and forth through pagination and everything works just fine. In this website section, which contain also the search form, I've implemented the search engine that bring search form result values in the same page. If you go to page 3 or 4 or 5 (for instance), and than you decide to filter items by picking some selects in the search form and submit them (while in page greater than 1), than search results items are retrieved keeping the current page (e.g. page 3 o 4 o 5 depending in which page I was when submitting the form), instead of returning items starting from page 1 So if you submit search form values while in page 3 (__.com/en/works/page3), you might even get results but they will be not visible as they might be not enough to reach page 3 (__.com/en/works/page3?expertise%5B%5D=value01 instead of start over __.com/en/works/?expertise%5B%5D=value01)
  4. I've get rid of the pagination function and did echo directly in template, which is actually even better in terms of simplification. echo $results->renderPager(array('arrayToCSV' => false)); However the issue is still there, if I am going to page 3 and then filter results from that page, then again I get correctly the results but they are hidden as they are not numerically enough to have at least 3 pages to show (and so the pagination disappear). The only way to make sure I see filtered results is by submitting the selection only from page 1.
  5. Thank you for sharing this, it looks interesting. Sorry for my layman point of view, but what exactly $items as argument retains? I guess the pages with specific template, isn't it? And when it comes to pass $selector as argument, which contains the submitted search form values, where should be located? Many thanks!
  6. I am basically call the pagination as a function, passing it the search form selectors as argument : function pagination($selector) { $works = wire('pages')->find($selector); if(count($works)) { echo $works->renderPager(array('arrayToCSV' => false)); } } the search form is essentially as described in a previous post: So maybe this issue is caused by the pagination function, as I am echoing it in the search form page as: <?php pagination($selector); ?> but i cannot figure it out why it doesn't restart from page 01 when user submit a search form..
  7. Thank you for the tip, I've tried the following combinations within the action="" brackets, with no luck (results from the search form should be displayed in the same page as per the form, page named "example"): "/example/" "/example" "/" "?" "/?" "?/" "" All the above options brings back either an error for the pagination module, or filtered items but not starting from page 1
  8. Hello PW community, I've a search form which return selected items with pagination. Everything works fine, also the pagination display correctly all results through pages. The issue is given only for selected results pagination as the latter does not start from page 1 but it revert back results from the current page (e.g. if you are in page 3, and submit a result from selects form, than all related items are displayed - not starting from page 1 but from page 3, which means something a fake "no results"). This is the classic function of render pager: echo $works->renderPager(array('arrayToCSV' => false)); Any idea? Thanks! Edit: I've also tried the "start=0" within the selectors, however it Always re-start from page 1 and stick to that, regardless. So no more option to move to page 2, 3, ....
  9. Thanks LostKobrakai, you pointed me in the right path by suggesting the static google map. I've achieved the above by simply doing this in the pages2pdf template: <img src="https://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&zoom=12&size=400x400&key=______"> which simply return a static image map. Useful enough!
  10. Hello PW Community, Do you know how to export current page's map as a pdf? Extended explanation: I have a template which has lots of fields, among which there is a field "geolocation" populated by the googlemapmarker module. Now, I wish to export the whole template as a pdf (with pages2pdf module), but the normal code that works on the ordinary pw's templates does not seems to work within the Pages2pdf dedicated templates. Below the code (working but not producing anything within Pages2pdf module): // alternative 01 <?php $map = $modules->get('MarkupGoogleMap'); echo $map->render($page, 'geolocation'); ?> // alternative 02 <?php $page = wire('page'); $map = $modules->get('MarkupGoogleMap'); echo $map->render($page, 'geolocation'); ?> Thanks in advance!
  11. Brilliant! I should pay you at least a couple of beers... I'll mark this thread as solved, thank you Robin for you inputs! regards
  12. As you recommended, reversing the position of the php processing code before the html form, made the trick and now the whitelist start populating - sorry to raise such silly issues... maybe you know what is the best approach on defining which input (checkbox in this case) should be marked as "checked" by matching the string value against the whitelist array. I mean, I get the "checked" feature for all the checkboxes, regardless of the options really selected. In_array works perfectly (thanks again!), I think I should first validate which option to check before outputting the $checked variable like the following. Do you have better suggestion? <form name='search' id='search-works' method='get' role='form'> <?php foreach($pages->get("/sectors/")->children() as $sec) { if(is_array($input->whitelist->cb_sectors)) { if(in_array($sec->name, $input->whitelist->cb_sectors)) { $selected = ' selected '; //$selected['selected'] = 'selected'; //Working alternative? } } echo " <p class='checkbox'> <input type='checkbox' name='cb_sectors[]' value='{$sec->name}' id='{$sec->name}' $selected/> <label for='{$sec->name}'>{$sec->title}</label> </p> "; } ?> <input class="class" type="submit" id="search-submit" name="submit" value="Search"> </form>
  13. Thank you Robin, I've made some testing and debugging (also with tracy debugger) to see what these variables keep while filtering. However everything seems working ok, except when it comes to retrieve data from the stored whitelist...well it says NULL (e.g. never an array, no data, nothing). I've only managed to retrieve the array by using $input->get instead of $input->whitelist : <?php foreach($pages->get("/sectors/")->children() as $sec) { $attrs = array(); if (is_array($input->get->cb_sectors)) { if(in_array($sec->name, $input->get->cb_sectors)) { $selected = ' selected="selected"'; } } echo "<option $selected value='{$sec->name}'>{$sec->title}</option>"; }?> which yes retrieve the array but now the issue is that I am going to select all option instead of the only active ones. Weird...
  14. I've tried many solution, none of them seem to retrieve correctly the array from the whitelist. The nearest solution to what discussed here is like the following: if(is_array($input->whitelist('cb_sectors'))) { //check if any array exists if(in_array($cb_sectors->name, $input->whitelist->cb_sectors)) { //if yes, match the value against the array echo "$cb_sectors->name is checked "; //just to display if working , but nothing outputs... } } //alternative to above if(is_array($input->whitelist->cb_sectors)) { //check if any array exists if(in_array($cb_sectors->name, $input->whitelist->cb_sectors)) { //if yes, match the value against the array echo "$cb_sectors->name is checked "; //just to display if working , but nothing outputs... } }
  15. Thank you Kongondo for your help, here the html code: <form name='search' id='search-works' method='get' role='form'> <?php foreach($pages->get("/sectors/")->children() as $sec) { if(in_array($sec->name, $input->get->cb_sectors)) { //$input->get->cb_sectors is supposed to be an array, but it outputs nothing instead... $selected = ' checked '; } echo " <p class='checkbox'> <input type='checkbox' name='cb_sectors[]' value='{$sec->name}' id='{$sec->name}' $selected/> <label for='{$sec->name}'>{$sec->title}</label> </p> "; } ?> <input class="mettiqualcosaqui" type="submit" id="search-submit" name="submit" value="Search"> </form> Here the processor code: <?php if(count($input->get)) { $selector = ''; //Selector to store selected inputs - and it should have "=" as it is the first in the list $selector .= "template=PageSingleWork, "; //Start concatenation, picking up all pages using this template if ($input->get->cb_sectors) { $se_array = array(); foreach ($input->get->cb_sectors as $se) { $sec = $sanitizer->selectorValue($se); $se_array[] = $sec; $selector .= "sectors=$sec, "; } $input->whitelist('cb_sectors', $se_array); } $works = $pages->find("$selector, limit=2"); //process the inputs to get filtered works $filtered = $pages->find($selector); //process the inputs to get filtered works $count = count($filtered); //count found works items if($count) { //found items and so display them echo "Found $count projects matching your search, using selectors ($selector)<br>"; { else { //no search results echo "Sorry, no projects were found that match, using selectors ($selector)<br>"; } } else { // do something } ?> I think the code in the frontend does not retrieve the whitelist array correctly, but all seem to be correct..
  16. I guess the $input->get->cb_sectors has to be array since it is checkbox group, but it says in the frontend: "Warning: in_array() expects parameter 2 to be array, null given"
  17. Thank you @kongondo, it's a newbie mistake and now I am testing it with in_array function, however seems hard to get the "checked" function work. Here the code: foreach($pages->get("/sectors/")->children() as $sec) { if(in_array($sec->name, $input->get->cb_sectors)) { //clearly wrong as it loops against empty array... $selected = ' checked '; } echo " <p class='checkbox'> <input type='checkbox' name='cb_sectors[]' value='{$sec->name}' id='{$sec->name}' $selected/> <label for='{$sec->name}'>{$sec->title}</label> </p> "; } Thank you @Robin S , it works like charm! thank you a lot to sort this out - I will post some final code as soon as it will be ready
  18. After several test, I am pretty sure the problem is given by the wrong white listing approach I am using with checkbox values (array). Here again the html checkbox field example (using "get" form): <?php foreach($pages->get("/taxonomy/status/")->children() as $st) { $checked = $st->name == $input->whitelist->st ? " selected='selected' " : ''; //HERE PART OF THE PROBLEM, IT DOES NOT CONSIDERING ARRAY echo " <p class='checkbox'> <input type='checkbox' name='st[]' value='{$st->name}' id='{$st->name}' $checked/> <label for='{$st->name}'>{$st->title}</label> </p> "; } ?> and this it's related process form: <?php if($input->get->st) { foreach($input->get->st as $st) { $san = $sanitizer->selectorValue($st); $san = $input->whitelist($st = ''); // THIS FOR ARRAY SEEMS NOT WORKING $selector .= "projectStatus=$san, "; //$input->whitelist('st', $san); //ALTERNATIVE TO THE ABOVE, AGAIN NOT WORKING FOR ARRAY } } ?> Someone already faced this issue (not storing the vars array in the whitelist or retrieve them) ? There are some posts in this forum but they look a bit outdated in terms of approach and not referring to the PW latest releases many thanks in advance!
  19. Thanks again Robin. Yes the template has already the pagination option checked. The weird thing is happening in the url string from page 2 on, as the URL in page 0 is as follow (which is almost ok, although still missing other checkbox empty values): .../?keywords=&cb_status%5B%5D=ongoing&submit=Search and from page 1 (or 2) the URL become like this (no more inputs...): .../?cb_status=array-1 which display clearly all items. It's something I cannot really figure out... I've also tried considering renderToCSV for pagination but no luck $pagination = $works->renderPager(array('arrayToCSV' => false)); It should be something related to the whitelist, I think i am not storing correctly the get vars
  20. Thank you @Robin S for your inputs! After tons of tentatives, I've got the whole search engine work. However, now the last missing part: let the pagination work with the search results, as by moving from the page nr. 2 onward, the selectors are not kept in memory/session thus no filter anymore. This is the code: <?php if(count($input->get)) { $selector = ''; //Selector to store selected inputs $selector .= "template=PageSingleWork, "; //Start concatenation, picking up all pages using this template if ($input->get->cb_expertise) { foreach($input->get->cb_expertise as $expertise) { // Sanitize it $exp = $sanitizer->selectorValue($input->get->cb_expertise); // Add it to the whitelist... with the same name as the get var! $input->whitelist('expertise', $exp); $selector .= "expertise=$expertise, "; } } if ($input->get->cb_sectors) { foreach($input->get->cb_sectors as $sector) { // Sanitize it $sec = $sanitizer->selectorValue($input->get->cb_sectors); // Add it to the whitelist... with the same name as the get var! $input->whitelist('sectors', $sec); $selector .= "sectors=$sector, "; } } $works = $pages->find("$selector, limit=3"); //process the inputs to get filtered works foreach($works as $work) { //here some work... } $pagination = $works->renderPager(); echo $pagination; } else { $works = $pages->find("limit=3"); //process the inputs to get all works as default foreach($works as $work) { //here some work... } $pagination = $works->renderPager(); echo $pagination; } Something wrong with the whitelist? Probably I have to put whitelist code also outside the foreach statement, in order to keep individual values? Or probably I have to declare the whitelist even in the html form? much appreciated, really
  21. Hello processwire community, this is my very first post, I am newbie in php - trying to test a simple search form which allow frontend user to search and filter data. Macro steps are as follow: 1) Create the form with options as checkboxes, allowing the user to choose multiple values selection within multiple checkbox groups; 2) Create the pw process code in order to revert back the selected items (as a result of multiple checkbox filter combination), allowing pagination as some results may be more than 50 items; --- Here some of the most related topics I've found over PW forum: https://processwire.com/talk/topic/7282-paging-issue-with-html-form-check-boxes/ https://processwire.com/talk/topic/3472-enable-pagination-for-search-results/#comment-38214 https://processwire.com/talk/topic/1883-how-to-use-input-whitelist-with-checkboxes-or-any-array/ https://processwire.com/talk/topic/1547-getting-multiple-checkbox-values-within-processwire/ https://processwire.com/talk/topic/1034-search-form-with-multiple-fields/ https://processwire.com/talk/topic/10193-multiselect-search/ --- Now, the html form works just fine (code below), it brings all checked values to the url string. Essentially I have four different groups of checkboxes: cb_sectors[] (multiple pages as categories); cb_expertise[] (multiple pages as categories); cb_status[] (multiple pages as categories); cb_year[] (integer). The user may select multiple values within the above four checkbox groups, thus creating even quite complex combination. <form name='search' id='search-works' method='get' role='form' action='<?php echo $pages->get('/search/')->url; ?>'> <div class="collapsible-header">Sector</div> <?php foreach($pages->get("/sectors")->children as $sec) echo " <p class='checkbox'> <input type='checkbox' name='cb_sectors[]' value='{$sec->name}' id='{$sec->name}'/> <label for='{$sec->name}'>{$sec->title}</label> </p> " ?> <div class="collapsible-header">Status</div> <?php foreach($pages->get("/taxonomy/Status")->children as $st) echo " <p class='checkbox'> <input type='checkbox' name='cb_status[]' value='{$st->name}' id='{$st->name}' /> <label for='{$st->name}'>{$st->title}</label> </p> " ?> <div class="collapsible-header no-padding">Expertise</div> <?php foreach($pages->get("/expertise")->children as $cb_expertise) $checked = $cb_expertise->name == $input->whitelist->cb_expertise ? " selected='selected' " : ''; echo " <p class='checkbox'> <input type='checkbox' name='cb_expertise[]' value='{$cb_expertise->name}' id='{$cb_expertise->name}' $checked/> <label for='{$cb_expertise->name}'>{$cb_expertise->title}</label> </p> " ?> <div class="collapsible-header no-padding">Year</div> <?php // generate a range of years from '09 to '17, or maybe better doing it via pages as years? for($year = 2009; $year <= 2017; $year += 1){ echo " <p class='checkbox'> <input type='checkbox' name='cb_year[]' value='$year' id='$year' /> <label for='$year'>{$year}</label> </p> "; } ?> <input class="no-class" type="submit" id="search-submit" name="submit" value="Search"> </form> The question is then mostly focusing on the second step, the pw process code: As some previous posts on this topic say - I should (in sequence) sanitize, whitelist and validate the results before pass them to the final output (correct me if I'm wrong). The thing is that I cannot find a way to get all values in a array and sanitize/whitelist/validate them -> some post suggest to use arraytoCSV as a way to let PW remember the filtered items while moving through pagination. Is arraytoCSV the best way to sanitize and whitelist the user input combination? The following code simply get selected values coming from the above form. As you can see, no sanitize nor whitelist nor validation is in place, as without the array the sanitizing function gives back only the last selected value (not the full combination for every group of checkboxes). Can you please help me implementing an array within the following code and the way to sanitize - whitelist - validate "get" values? I know for most of you is just as simple as drinking coffe, but would be great if you could drive me in the right direction. Thank you in advance! <?php namespace ProcessWire; if(count($input->get)) { if($input->get->cb_expertise) { foreach ($input->get->cb_expertise as $expertise) { // here we are just ensuring submitted products are in fact valid echo $expertise; } } if($input->get->cb_sectors) { foreach($input->get->cb_sectors as $sector) { // here we are just ensuring submitted products are in fact valid echo $sector; } } if($input->get->cb_status) { foreach($input->get->cb_status as $status) { // here we are just ensuring submitted products are in fact valid echo $status; } } if($input->get->cb_year) { foreach($input->get->cb_year as $year) { // here we are just ensuring submitted products are in fact valid echo $year; } } } ?>
×
×
  • Create New...