Jump to content


  • Posts

  • Joined

  • Last visited

Everything posted by jds43

  1. Thanks @kongondo for taking the time to prepare all of this!
  2. So, I have htmx working, but it's replacing the deleted card with the whole page. Odd, but I probably have some settings wrong: $out .= "<div hx-post='./' hx-vals='#card-$item_id' hx-target hx-ext='ajax-header' class='".(($row) ? 'uk-width-1-3' : 'uk-width-expand')."'> <div class='image uk-card-media-top uk-background-cover uk-position-relative ".(($row) ? 'rad' : 'rounded-top-left-right')."' $img data-uk-img> <span class='uk-position-top-right uk-position-small uk-preserve' data-uk-icon='icon: heart; ratio: 2'></span> </div> </div>";
  3. Hello @kongondo, could you provide the full code? I'd like to try applying it to my project. Thank you!
  4. Thanks @Rudy and @Pixrael! I wasn't aware urlSegment would not capture URL query strings. I went this route: if(!isset($_GET['publish_from']) || !isset($_GET['publish_until'])) { // output only on /events/ }
  5. Hello, I would like to output content on a template at the url /events/, but not /events/?publish_from=2021-08-24&publish_until=2021-08-31. Tried using the wildcard character as referenced here, but no dice. Does anyone know to achieve this? $segmented_events = $input->urlSegment('publish_(*)'); if(!$segmented_events) { // output only on /events/ }
  6. Thank you @kongondo That's pretty amazing for a rough example 😁
  7. Got it @Jan Romero I counted the card-wrap elements and updated the innerHtml of the span after the cards were removed by the request. Thank you very much!
  8. Hello @kongondo I'm certainly curious about htmx. Yes please, to preparing a rough example.
  9. Thanks @Jan Romero This is so cool! It works like a charm. However, I have an alert that counts the matches that will need to be refreshed also. Any ideas? $matches = $pages->find("id=$selector, template=place, limit=20"); if($matches->count) { echo "<div class='uk-alert-primary' data-uk-alert> <a class='uk-alert-close' data-uk-close></a> <h2 class='uk-text-center'>$matches->count ".(($matches->count == 1) ? 'item' : 'items')." in Your Itinerary:</h2> </div>"; }
  10. Hello, I have a listing of locations where the user is able to click a link within each card to add/remove. The session is altered by query strings based on the id of the location. It functions well, but requires the page to be reloaded. <a href='{$page_url}?id=$item->id'> I'd like to use AJAX for adding or removing locations, updating the session and reloading the listing without page reload. I created a template ajax.php and added to PW with a hidden page using the template. The template just outputs placeholder markup wrapped in $config->ajax condition. The basic script I've tested reveals the placeholder markup when clicked, but I'll need the listing to display on page load and refreshed on clicking of the add/remove link within each location. <script> function loadDemo() { const xhttp = new XMLHttpRequest(); xhttp.onload = function() { document.getElementById("demo").innerHTML = this.responseText; } xhttp.open("GET", "/ajax-test/", true); xhttp.send(); } </script> I've referred to many forum posts and can't quite find a solution for this situation. Can anyone lend some guidance for using AJAX for adding or removing locations, updating the session and reloading the listing of locations by clicking a link with a query string?
  11. @Robin S you are my hero! It works perfectly.
  12. Thanks @Zeka No luck with the following change. The session persists. Any ideas? if(isset($_GET[$key])){ if(is_array($session->itinerary)) { // destroy a single element of an array $session->remove($key); $session->redirect($page->url); } }
  13. Hello, I'm wanting to allow the user to remove a key from their session, that had been created by previous form input, by clicking a link with a query string. The condition runs, but I'm getting the following error with no changes to the session. PHP Notice: Indirect modification of overloaded property ProcessWire\Session::$itinerary has no effect I imagine the session is protected from accessing this way. Does anyone have any suggestions? foreach($session->itinerary as $key => $value) { echo "<li class='uk-text-capitalize uk-flex uk-flex-row uk-flex-middle'> <a href='$page->url?$key=true' data-unset='$key' data-uk-icon='icon: minus-circle'></a> The ".str_replace("-", " ", $key)." </li>"; if(isset($_GET[$key])){ if(is_array($session->itinerary)) { // destroy a single element of an array unset($session->itinerary[$key]); $session->redirect($page->url); } } }
  14. I placed this within each input of the form based on the name of the field and it works. if(is_array($session->itinerary) && array_key_exists('foodie', $session->itinerary)) echo 'checked'; Still not clear about sanitizing the input from the initial form submittal though.
  15. Hello, I have a custom form featuring 9 checkboxes. The user makes their selections and submits to set a session called "itinerary" with key (foodie) and value (1) for each selection. How can I populate those checkboxes based on the "itinerary" session when the form is viewed again. I've referenced Skyscrapers, but wasn't able to apply it here. Also, would I need to sanitize user input for a checkbox? If so, would I do so in the loop before whitelisting? ($value = $sanitizer->selectorValue($value)) if(isset($_GET['submit'])) { // Remove existing "itinerary" sessions $session->remove('itinerary'); // Loop through all inputs to create an associative array for storing selected checkboxes in session foreach($input->get() as $key => $value) { $value = (int) $value; $input->whitelist($key, $value); $itinerary[$key] = $value; } $session->set("itinerary", $itinerary); $session->redirect($page->url); } echo "<pre>".var_dump($session->itinerary)."</pre>"; array(4) { ["foodie"]=> int(1) ["love-birds"]=> int(1) ["family"]=> int(1) ["submit"]=> int(1) }
  16. I prefer your approach @netcarver It appears to be working quite well. Thank you for that option.
  17. Thanks for the help @netcarver 👍🏼
  18. Comparing the array_keys wasn't working, so I changed to the following. Seems to be working. // Generate associative array of repeater items by title $usgs_repeater = $usgs_data->explode('title'); // Flip keys and values $usgs_repeater = array_flip($usgs_repeater); // Returns an associative array containing all the entries which have keys that are present in all arguments $usgs_count = array_intersect_key($usgs_repeater, $sessions); // Count the entries $usgs_count = count($usgs_count); if($usgs_count !== count($usgs_repeater)) { // Do the thing }
  19. Thanks @netcarver I tried a variety of approaches from array_intersect to array_diff. I think the following has worked. Not really sure how to confirm aside from clearing session data, but I'm not seeing any errors in Tracy. if(array_keys($usgs_repeater) === array_keys($sessions))
  20. Hello, I need to run a script when specific sessions aren't active, but my code doesn't seem to be working. Are there any glaring errors // Generate associative array of repeater items by title $usgs_repeater = $usgs_data->explode('title'); // Get all session variables in an associative array $sessions = $session->getAll(); // Check if titles of USGS Repeater items are active sessions to execute WireHttp for location data if(!in_array($usgs_repeater, $sessions)) { // Do the thing here } Or should I check the array like this: if(in_array($usgs_repeater, $sessions)) { return; } else { // Do the thing here }
  21. 😃 looks like that did the trick! Thanks @Ivan Gretsky!
  22. Thanks @Ivan Gretsky So, how would I set that value when I keep getting /events/page2 instead of /events/page2/?publish_until=2020-12-31 when I select the next paginated page for date filtered results?
  23. Hello, I'm trying to paginate results that may have Url Segments and I want to modify the Base Url. How do I accomplish this within renderPager? I found docs here: https://processwire.com/api/ref/markup-pager-nav/render/, but it hasn't pointed me in the right direction. $pager->setBaseUrl(string $url); echo "<div id='pagination' class='uk-container uk-container-medium uk-margin-large-top'>"; echo $matches->renderPager(array( 'nextItemLabel' => "Next", 'previousItemLabel' => "Prev", 'currrentItemClass' => "uk-active", 'listMarkup' => "<ul class='row uk-flex-right'>{out}</ul>", 'itemMarkup' => "<li class='{class}'>{out}</li>", 'linkMarkup' => "<a href='{url}' class='uk-button uk-background-secondary'><span class=''>{out}</span></a>", )); echo "</div>"; Or, does anyone know of a better option?
  24. Hello, I'm trying to list the categories, on the front through select options, that have been selected by page reference field (multiple pages PageArray) on the child pages. Things to Do (would only display three, six, seven, nine in select) -thing one (-category three, -category nine) -thing two (-category six, -category seven) Lodging (would only display one, two, three, four in select) -lodging one (-category one, -category two) -lodging two (-category three, -category four) Dining (would only display five, six, seven, eight in select) -dining one (-category five, -category six) -dining two (-category seven, -category eight) Categories(hidden page) -category one -category two -category there -category four -category five -category six -category seven -category eight -category nine -category ten $categories = $pages->find(1129)->children('include=hidden'); foreach($categories->references('category') as $ref) { echo $ref->title; } This selector isn't working, but it seems 'references' would be helpful. I've never used it before, so I'm not sure how to employ for this. https://processwire.com/blog/posts/processwire-3.0.107-core-updates/#page-gt-references
  • Create New...