Jump to content

jds43

Members
  • Posts

    96
  • Joined

  • Last visited

Posts posted by jds43

  1. I have a large selection of location cards rendered by a function in _func.php, successfully paginated to 12. Within the cards, I'm using an onclick event in JS to perform an async request utilizing the url of a link referenced as a property ($page_url = $page->url) of the function. It only works on the first page. After that, the async function doesn't work properly because the url of the link in the card is localhost:8888/results/?add=2353 instead of localhost:8888/results/page2/?add=2353.

  2. Hello,

    I'm using an API to return a collection of zip codes within a radius of a particular zip code the user will input. These will populate a list of locations, but I'm having trouble promoting the zip code input by the user to the top of the list. Sort isn't working at all.

    ZIP is the location page zip code field.
    $city_or_zipcode is the sanitized input.
    $selector is the decoded JSON response as string for zip codes separated by pipes.

    $producers = $locations->children("(ZIP=$city_or_zipcode), (ZIP=$selector), template=producer, limit=24");

    I've even prepended the searched user zip code to $selector and it doesn't help either.

    Any ideas?

  3. 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>";

     

  4. 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/
    }

     

  5. 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>";
                    }

     

  6. 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?

  7. 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);	
            }
        }
    }

     

  8. 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) }

     

×
×
  • Create New...