Jump to content

ZionBludd

Members
  • Posts

    42
  • Joined

  • Last visited

Posts posted by ZionBludd

  1. Hi, on my website I have the comments system implemented across each store page. I am wanting to see if their is a built in function to allow to bring in all of the comments for a particular brand into one page

    Store Listing 1 (Belongs to store brand XYZ)

    Store Listing 2 (Belongs to store brand XYZ)

    Store Brand Listing Page (Lists all of the store listings, plus all of the comments from Store listing 1 & Store Listing 2)

     

  2. Hi Team,

    I am wondering how I would go about logging an entry either in the database (e.g. a field) or through the $log function?

    My site is a price comparison tracker and I am hoping to be able to present data to people advertising on my site if they click on a link?

    Another solution I guess I could use would be Google Analytics, but would be nice to have something inside PW.

     

  3. Hi, I'm having an issue where my form won't respond to my post form if I'm on any other page other than Page 1 of a set of pagination results.

    Is this a limitation of pagination? Has anyone else came across this? 

  4. 6 hours ago, Robin S said:

    Hi Matt,

    Your code looks like it should work okay so not sure why it isn't. But a few general observations...

    Making the connection between pages with the Listing template and pages with the PriceSpy template via only the title is not very robust. What if one of these pages needed to change title? You'd then have to do maintenance on all related pages or else the connection would break. I think it would be better to make the connection via Page Reference fields or possibly a parent-child relationship.

    Using a text field for prices is not ideal, and I think you should exclude the currency symbol from the field (I'm assuming the $ sign is in the field because I can't see it being added separately in your code). Better to use a decimal field type and prepend the currency symbol in your template. Then there would be fewer complications with sorting like you're experiencing now. 

    It looks like you're using a templating language (is that Smarty?), but there is business logic in the template also which sort of defeats the most common reason for choosing to use a template language separate from PHP. If you're not bothered about enforcing a strict MVC pattern it would be simpler just to stick to plain PHP in your template files.

    Thanks heaps for your suggestions, Robin. I am looking to improve the structure over the weekend & will take these on board

     

    5 hours ago, tpr said:

    Perhaps you need to change this

    
    $pages->find("template=PriceSpy, sort=price, title=$item_title, limit=1") 

    to this:

    
    $pages->find("template=PriceSpy, sort=price, title=$item_title")->first()

     

    Thanks tpr, Will look into this! 

    • Like 1
  5. Hi Team, I am having trouble sorting prices in my foreach loop and am wondering is becasuse my price field is a text field and not a number field.

    My code is 

    <?php
    $item_title = $item->title;
    $items = $pages->find ("template=Listing, limit=15, sort=title");
    foreach ($items as $item??>
    <tr>
    <td>{item.brand}</td>
    <td>{item.model}</td>
    <td>
    <?php $item_title = $item->title;
    $store_price = $pages->find ("template=PriceSpy, sort=price, title=$item_title, limit=1") ;
    foreach ($store_price as $price) :?>
     
    {price.price}
     
    <?php endforeach ;?>
     
     
    </td>
    <td>
    <?php $item_title = $item->title;
    $store_price = $pages->find ("template=PriceSpy, sort=-price, title=$item_title, limit=1") ;
    foreach ($store_price as $price) :?>
     
     
    {price.price}
     
    <?php endforeach ;?>
     
     
    </td>
    </tr>
    <?php endforeach ;?>

    The offending page is this one: https://www.vapeprices.co.nz/price-guide/. Whereas you can see the Low and High columns are just not making sense

    I would really appreciate any help.

  6. Hi All, I am wondering if anyone has come up with an easier way of merging their local environment with the live production environment. 

    For instance, my thinking would be to use Site Profile Exporter, install Processwire in the main directory of the live environment & install. Just to clarify, This is if I am doing a lot of structural changes obviously to both the template fields level and the templates themselves. 

    Otherwise, it would be just the normal (keeping two copies in sync and uploading etc).  

    Does anyone have any solutions? 

  7. Hi All, I am wondering if anyone has a solution to my problem.

    I have a website that I have at a DomainA.com, but I am wanting all templates/static assets (such as images uploaded by the user, PW, etc) to be assets.domaina.com

    Is this possible? From what I've read in the forums - you need to use some special htaccess code, but the posts are from a few years ago.

  8. Hi guys, I am wondering how I deal with this error message. Whenever I am trying to save a page I am getting this error when someone enters the same name in the "name" textbox. 

     

    Here is my code 

    <?php	if ($input->post->reviews || $input->post->name) {
    
    						  // Save in the ProcessWire page tree; map submission to the template fields
    						  $np = new Page(); // create new page object
    						  $np->template = $templates->get("reviews");
    						  $np->parent = $pages->get("/reviews/");
    
    						  $name = $sanitizer->text($input->post->name);
    						  $email = $sanitizer->text ($input->post->email);
    						  $review = $sanitizer->text ($input->post->review);
    
    						  // Match up the sanitized inputs we just got with the template fields
    						  $np->of(false);
    						  $np->title = $name;
    						  $np->page_id = $page->id;
    						  $np->name = $name;
    						  $np->email = $email;
    						  $np->review = $review;
    						  $np->save();
    						}
    						?>

     

  9. 18 hours ago, louisstephens said:

    I believe you would still have to foreach through the options like:

    
    foreach($page->name_of_select as $option) {
    	echo "<li>$option->title</li>";
    }

     

    Thanks for all of your help. I managed to get the desired end result using Ryan's example: 

     

    • Like 1
  10. Just now, dragan said:

    I don't really understand your question. Please explain "directly" and "field type"? PW inputfield types?

    Just curious, if I had a select input by the name of "type" - Can I call that directly and output the options

  11. 1 minute ago, dragan said:

    Create a "settings" template (name it whatever you want). You only need one field: title (or multilang title).

    Create a page somewhere. That will only serve as a parent / container page.

    Create as many pages underneath this parent page as needed. One page per select option.

    Then, in the template you want to build your form, basically do something like

    
    $settings = $pages->get(123)->children; // 123 is the id of the parent page
    foreach($settings as $s) {
        echo "<option value='{$s->title}'>{$s->title}</option>";
    }


    Thanks, you can't directly output a field type? 

     

  12. 2 minutes ago, dragan said:

    That's a classic use-case for page reference fields.

    Create a dedicated page that acts as parent for all your product types. Underneath, create a page for every product option.

    Then you can easily foreach($page->children) etc.

    Thanks for your reply, can you give me an example of how I might implement this? 

  13. Hi, I am wondering if there is a better way to output a field's options

     Currently I am basically adding types as they are required, but I can see the types growing - and wondering if I can call directly from the field?

     <select name="product_type" class="form-control" style="font-size:9pt">
              <option value=""><?php echo $NO_SELECT_PRODUCT; ?></option>
              <option <?php if ($pt == "Starter Kits"){echo 'selected';};?> value="Starter Kits">Starter Kits</option>
              <option <?php if ($pt == "Advanced Kits"){echo 'selected';};?> value="Advanced Kits">Advanced Kits</option>
              </select>

     

  14. Thanks so much for all of your responses. Such an amazing community. 

    I've done a-lot of reading, and debugging with TracyDebugger and this what what I've come up with

    
    <?php
    $limit = null;
    $sort = null;
    $template = null;
    $kit_type = $session->get('search_type');
    
    if ($page->path == "/kits/starter-kits/") {
      if ($input->post->product_brand_name || $input->post->limit || $input->post->product_type || $input->post->product_port_location) {
        $session->set ('template', 'products');
        $session->set ('limit', $input->post->limit);
        $session->set ('product_type', $input->post->product_type);
        $session->set ('product_brand_name', $input->post->product_brand_name);
        $session->set ('port_location', $input->post->product_port_location);
        // Build selector
        $selector = "template=$session->template, product_brand_name=$session->product_brand_name, product_port_location=$session->port_location,limit=$session->limit, product_type=$session->product_type";
        var_dump ($selector);
    
      } else {
        $session->set ($product_type , 'Starter Kits');
        $selector = "template=products, sort=name, product_type=$session->product_type";
        echo "<pre style='padding:10pt'>";
        echo "Default Starter Kits landing settings";
        echo "<br>";
        var_dump ($selector);
        echo "</pre>";
    
    
      }
    } elseif ($page->path == "/kits/advanced-kits/") {
      if ($input->post->product_maker || $input->post->limit || $input->post->product_type || $input->post->product_port_location) {
        $session->set ('template', 'products');
        $session->set ('product_maker', $input->post->product_maker);
        $session->set ('limit', $input->post->limit);
        $session->set ('product_type', $input->post->product_type);
        $session->set ('port_location', $input->post->product_port_location);
        // Build selector
        $selector = "template=$session->template, product_port_location=$session->port_location, product_maker=$session->product_maker, limit=$session->limit, product_type=$session->product_type";
        var_dump ($selector);
    
      } else {
        $session->set ('product_type' , 'Advanced Kits');
        $session->set ('product_maker' , '');
    
        $selector = "template=products,sort=price, product_type=Advanced Kits";
        echo "<pre style='padding:10pt'>";
        echo "Default Advanced Kits landing settings";
        echo "<br>";
        var_dump ($selector);
        echo "</pre>";
    
    
    }
    
    } elseif ($page->path == "/kits/advanced-kits/") {
        if ($input->post->product_maker || $input->post->limit || $input->post->product_type || $input->post->product_port_location) {
          $session->set ('template', 'products');
          $session->set ('product_maker', $input->post->product_maker);
          $session->set ('limit', $input->post->limit);
          $session->set ('product_type', $input->post->product_type);
          $session->set ('port_location', $input->post->product_port_location);
          // Build selector
          $selector = "template=$session->template, product_port_location=$session->port_location, product_maker=$session->product_maker, limit=$session->limit, product_type=$session->product_type";
          var_dump ($selector);
    
        } else {
          $session->set ('product_type' , 'Advanced Kits');
          $session->set ('product_maker' , '');
          $session->set ('limit', '10');
          $selector = "template=products,sort=price, limit=$session->limit, product_type=Advanced Kits";
            if ($user->isSuperuser()){
              echo "<pre style='padding:10pt'>";
              echo "Default Advanced Kit landing settings";
              echo "<br>";
              var_dump ($selector);
              echo "</pre>";
            }
    
      }
    
    }
    elseif ($page->path == "/kits/intermediate-kits/") {
        if ($input->post->product_maker || $input->post->limit || $input->post->product_type || $input->post->product_port_location) {
          $session->set ('template', 'products');
          $session->set ('product_maker', $input->post->product_maker);
          $session->set ('limit', $input->post->limit);
          $session->set ('product_type', $input->post->product_type);
          $session->set ('port_location', $input->post->product_port_location);
    
    
          // Build selector
          $selector = "template=$session->template, product_port_location=$session->port_location, product_maker=$session->product_maker, limit=$session->limit, product_type=$session->product_type";
          var_dump ($selector);
    
        } else {
          $session->set ('product_type' , 'Intermediate Kits');
          $session->set ('product_maker' , '');
          $session->set ('limit', '10');
          $selector = "template=products,sort=price, limit=$session->limit, product_type=Intermediate Kits";
            if ($user->isSuperuser()){
              echo "<pre style='padding:10pt'>";
              echo "Default Intermediate Kit landing settings";
              echo "<br>";
              var_dump ($selector);
              echo "</pre>";
            }
    
      }
    
    }
    
    ?>

    However, haven't been able to implement post resubmission errors (Post Get Redirect method)

    And I'm having trouble with removing the product_brand_name selector when it's not selected in my form.

  15. Hi, I am currently in the process of converting over some friends code from pure PHP code to the PW API. However, I've come into a road block with $_SESSION.

    Can someone explain to me the PW equivalent of PHP's $_SESSION. What I am doing below is preventing the page doing another post on a page refresh, using the Post/Redirect/Get method. 

    <?php
      //var_dump($_POST);
      if($_SERVER["REQUEST_METHOD"] == "GET"){
        //check for filter action
        if(isset($_SESSION["filter"])){
          $template = $_SESSION["filter"]; //this is your templates
          //things should just  work.
          $_SESSION["filter"] = null;
        }
        else{
          if ($page->id == "1019") {
            $template = "product_maker=NULL";
            $template = "template=products, product_type=Starter Kits,sort=name";
            // Defaults for fields
            $_SESSION["product_type"] = $_SESSION["product_maker"]  = $_SESSION["limit"] = null;
           }
        }
    
        if(isset($_SESSION["product_type"])){
          $product_type =  $_SESSION["product_type"] ;
        }
        if(isset($_SESSION["product_maker"])){
          $product_maker =  $_SESSION["product_maker"] ;
        }
        if(isset($_SESSION["has_images"])){
          $has_images =  $_SESSION["has_images"] ;
        }
        if(isset($_SESSION["limit"])){
          $limit =  $_SESSION["limit"] ;
        }
        var_dump($_SESSION["product_type"]);
      }
      else if($_SERVER["REQUEST_METHOD"] == "POST"){
    
        if ($input->post->$sanitzer->product_type || $input->post->has_images || ($input->post->$sanitzer->product_maker || ($input->post->limit)))  {
            $_SESSION["product_type"] = $product_type = $input->post->product_type;
            $_SESSION["product_maker"] = $product_maker = $input->post->product_maker;
            $_SESSION["has_images"] = $has_images = $input->post->has_images;
            $_SESSION["limit"] =$limit = $input->post->limit;
            $template = "template=products, has_images=$has_images, product_maker=$product_maker, limit=$limit, product_type=$product_type";
    
    $template;
    $_SESSION["filter"] = $template;
    
          }
        elseif ($input->post->has_images) {
         $template = "template=products";
        }
        //else {
        //    $product_type = $input->post->product_type;
        //}
        $_SESSION["filter"] = $template ;
    
    
        header("Location: ".$_SERVER['REQUEST_URI']);
        exit();
    //redurect to self.
    
      }
    ?>

     

    • Like 1
  16. Hi, I am wondering if someone can help me out with getting the count of the comments of a page? 

    I am using Ryan's comments module as a reviews system for my site and would like to display the count of the comments per page, as below 

     

    Screen Shot 2018-05-07 at 7.57.37 PM.png

     

    The shops part that you see above is something similar to this 

    <?php $set_page = $page->title;
    $count = $pages->count("template=prices, title=$set_page");
    echo $count;
    ?>

     

  17. Thanks so much for your efforts! You put me in the right direction, I ended up going for the page create function vs storing in the user->favs way. Manly because my friend who is helping me with this is a software developer and he stays clear of frameworks.

    This is my code for detecting the input button.

    <?php if ($input->post->add_fav) {
    
        // Save in the ProcessWire page tree; map submission to the template fields
        $np = new Page(); // create new page object
        $np->template = $templates->get("Favorites");
        $np->parent = $pages->get("/favorites/");
      ?>

    On the results page in each item I have the following code

    <form action="./" method="post"><button type="submit" value="{dbResult.id}" name="add_fav">Add Favorite</button>
    </form>

    And then finally this is the most stop gap measure system to actually view the favorites, and I'm sure you'll be able to point out that it is very prone to bugs and security holes

    <?php
    $id = $user->id ;
    
    $get_favs = $pages->find("template=Favorites, user_id=.$id.");
    foreach($get_favs as $fav) {
        echo "<li><a href='$fav->url'>$fav->product_id</a></li>";
    }
    ?>

    Thanks again for your help, What do you think? Are you shuddering :) 

  18. Hi All, I am wondering if you could provide input on the best way an item as a user favorite.

    I am setting up a price comaprison website, and have most of the logic done for the site. Search results, listing page, login/logout, search, etc. It's all looking pretty good. However someone has suggested to me that users might like to save an item as a favorite.

    So my idea behind that was to have a button on each of the grid items in the search results page. 

    This is my search results page code with the button within the item.

    <form id="add_fav" name="add_fav" autocomplete="off" accept-charset="utf-8" action="./" method="post">
      <button class="wish_btn" name="add_fav">Add Fav</button>
    </form>

    Where the business logic is on the page, this is what I have so far - I just don't know how to align an item to a user.

    $log->save ('pageview', 'testing');
    function clense_input($data){
                $data = trim($data);
                $data = stripslashes($data);
                $data = htmlspecialchars($data);
                return $data;
            } 
          
            $sort = "title";
    
            // Logic for favorites
    
            if ($_SERVER["REQUEST_METHOD"] == "POST") {
              if (isset($_POST['add_fav'])) {
                $favs = $sanitizer->text($_POST['add_fav']);
                if(!empty($favs)){
                  $ticket = $pages->get($favs); // Set page name 
                  if($favs != null){
                    $favs->of(false);
                    $favs->fav_title = $page->user->name; // Save username
                    $favs->fav_title = $page->title->id; // Save page id to favs list
                    $favs->save();
                    echo "Fav saved.";
                  }
                }
              }
          }

     

  19. Hi guys, I'd really appreciate some help from you. I am wondering how I would about using the Selector field type within a repeater.

    It seems kinda bad design to have multiple selectors (e.g. Grid 1, Grid 2, Grid 3) when I could use a repeater for it.

    Using Ryan's example, I have managed to get my repeater to work

    foreach($page->grid_repeater as $grids) {
      echo "<h2>{$grids->grid_type}</h2><p>";
    echo "
    
    }

     

×
×
  • Create New...