Jump to content

SamC

Members
  • Posts

    733
  • Joined

  • Last visited

  • Days Won

    9

Posts posted by SamC

  1. @rick yeah, I can see the changes now on the page when I change things inside the ___execute() methods. The part that I was changing was here:

      public static function getModuleinfo() {
        return [
          "title" => "Simple admin example",
          "summary" => "No need to be afraid of building custom admin pages.",
          "author" => SamC",
          "version" => 1,
    
          // page that you want created to execute this module
          "page" => [
            // your page will be online at /processwire/simple/
            "name" => "test", // <<<<<<<<< I CHANGED THE PATH HERE
            // page title for this admin-page
            "title" => "Hello",
          ],
        ];
      }

    Had to uninstall and reinstall for this change to be reflected. Anyway, getting sidetracked as usual.

    1 minute ago, Sergio said:

    Beware of the large JS load that comes with Discuss, that's why I load it only if the user clicks the "Comments" button. It's possible to show the current comment count, calling the discuss API, but I didn't want it. 

    I was thinking of just having the comments button, no need to load it up all the time. Not sure how people would even use it but I needed a reason to make a module, and here it is :) 

    • Like 1
  2. Some great resources to get me started, thanks!

    Following this one at the moment: https://processwire.com/blog/posts/building-custom-admin-pages-with-process-modules/

    One thing, how I do I see changes in the module as I go along? When I make a change, I tried clearing cache but changes are not reflected, specifically, the page created in the getModuleInfo() method, for me at '/login/test/'. I changed the path in my code but the only thing that's worked so far was uninstall > reinstall. Is there an easier way?

  3. I was going to add comments to my site and wanted to use disqus. I looked through the manual adding of this but thought this might be a good opportunity to learn how to make a module as I can't find one in the directory. Was thinking having a few fields or something, where config options can be set and they are then output somehow into the JS embed code. Not really sure about how any of it would work yet but gotta start somewhere.

    You'll notice on the disqus page that many other CMSs have dedicated plugins/modules to install it, so I'm looking to create the PW one. The manual instructions for disqus are here:

    https://help.disqus.com/customer/portal/articles/472097-universal-embed-code

    My immediate problem is, what category is a module like this? And what class would I extend? 'extends Process', 'extendsWireData' etc. It's not clear to me on the api page how you'd choose and reading the code from the base classes probably wont switch on any lights here.

    https://processwire.com/api/ref/module/

    Maybe I'm biting off a little more than I can chew, but what the hell, it'll be a good learning experience, and maybe produce something useful at the end of it. I'll be digging into @bernhards process module tutorial this weekend but I don't think this is a process module.

    • Like 3
  4. 2 hours ago, Pixrael said:

    In BS4 (in BS3 too) you can on/off the inclusion of any component (javascripts or styles) in your project, it's not mandatory to download and use the whole framework

    This totally. If you install via npm you can use gulp to compile the scss. Create your own variables file, @import that, then @import whatever components you want, finally @import your custom styles. It's worth noting though, that although you can pull in 'just' a few components, on their own, these components are still a fair bit larger than a lean custom solution.

    I'm actually moving away from BS4 to Uikit 3 because it's more modular and I quite liked it after mucking around with the new admin theme.

    30 minutes ago, pwuser1 said:

    css grid is not responsive?

    Hi @pwuser1 and welcome. Yes, css grid is responsive. Check out this pen (not mine): 

    In all honesty, I wouldn't worry about css grid right now. It's just too new. Flexbox has only just gained enough browser support for me to switch over from floats (I loved bourbon/neat combo, alas, the new neat is still floats). But that combo gave me some super lean HTML markup,100% mixin based!

    No harm in learning it though for when it's ready for prime time, this is quite fun: http://cssgridgarden.com/

    • Like 2
  5. I read the opening post earlier and I was like wha? Just now I loaded up my localhost pw.tuts.dev and BOOM! "Your connection is not private". The same damn site I was working on like 6hrs ago without issue. Now I gotta change my hosts and vhosts and all that crap. Looks like I'll be going down the .local route.

    Thanks for the answers here everyone.

    • Like 1
  6. 6 minutes ago, Robin S said:

    // get catType page
    $catType = $pages->findOne("parent=/type/, name=$segment1");

    Absolutely this, I like it!

    6 minutes ago, Robin S said:

    Not sure in what way you were considering using has(), but that method is for checking against a PageArray/WireArray that is already loaded to memory - better to load just the page (category) you want than to load many just to filter it down again.

    I couldn't work out the use for it,  I see now. Thanks :) 

    • Like 1
  7. I'm writing a tutorial about URL segments and I have it working like this (ignore overly verbose comments).

    Cats (cat-index template)
     - cat 1 (cat-entry template)
     - cat 2
     - cat 3

    Type (cat-attribute template, each child is a page ref field on cat-entry template)
     - Burmese (cat-attribute template)
     - Tabby
     - Persian
     - etc.

    Invalid is 2nd URL segment and anything else in URL segment 1 that isn't the page name under /type/.

    Valid
    /cats/tabby/
    /cats/persian/
    etc...

    Invalid
    /cats/first/
    /cats/first/second/

    <?php
      // only 1 URL segment should be allowed
      if ($input->urlSegment2) {
        throw new Wire404Exception();
      }
    
      // create a string that will be our selector
      $selector = "template=cat-entry";
    
      // get URL segment 1
      $segment1 = $input->urlSegment1;
    
      // if there is a URL segment 1
      if ($segment1) {
        // get array of cat type page names
        $catTypes = $pages->get("/type/")->children->each("name"); // name may be assumed here, not sure
        
        // if URL segment 1 is in cat types array
        if (in_array($segment1, $catTypes)) {
          
          // add this to the selector
          $selector .= ",catType=$segment1";
        }
        else {
          // invlid URL segment 1
          throw new Wire404Exception();
        }
      }
    
      // find the pages based on our selector
      $catPages = $pages->find($selector);
      foreach ($catPages as $catPage):
    ?> 

    Now this works, 404 for anything invalid.

    But I was looking at https://processwire.com/api/ref/wire-array/has/ and it seems to be similar.

    Is the code above a suitable way to achieve this? (bearing in mind this is a tutorial so trying to stick with best practices)

    And how would I use has() in the above example? Not 100% how to use that method i.e. is ->has() used inside a loop?

    (unfortunately can't link to the actual tut as it's unpublished)

  8. 13 hours ago, szabesz said:

    It would not be explicit but another thing I forgot to note is that there is no /product-categories/ nor /skin-concerns/ pages accessible by design, so what would happen if someone tried to go there?

    I see the point, but I would personally expect a page /product-categories/ and the same at /skin-concerns/ which lists the actual menu items (in the right sidebar) but if they're not there by design then URL segments are win :) 

    • Like 1
  9. 5 hours ago, FrancisChung said:

    Is this something that you can truly ignore? AFAIK your Google Pagespeed score does impact your SEO rankings. Otherwise, I would love to heed your advice and ignore what Google has to say.

    I guess it depends on how you expect to find visitors. Imagine spending a few days trying to optimize for pagespeed to please almighty google (and maybe get some random tyre kicker search visitors), then think that you could have done a facebook/twitter campaign, or even physically went out to find customers in that same time instead and maybe get some serious leads.

    For what I'm doing, word of mouth is going to be far more important than shaving a few milliseconds off pagespeed. You just have to use your time wisely, if pagespeed is important and will benefit you directly, then sink a few days into it.

    ps if you find a way to ever get rid of "Eliminate render-blocking JavaScript and CSS in above-the-fold content", then please let me know. Inline css is bad, let's use separate stylesheet files. Actually let's combine them into one file, and let's minimize them. No, let's use webpack to use JS to pull in CSS inline. No, let's just load a small part of CSS 'above the fold' and the load the rest later. What about smart watches?

    At this rate, we don't need to worry about IPv4 running out, everyone's too busy optimizing existing sites and learning tools to make anything new.

    • Like 2
  10. Hi @adrian to be fair, I haven't really sat down and tried to learn it properly. When I do this, I could always document it and use what I learned for a small tutorial for beginners. I'm seeing most things I do in this way at the moment and I've found that documenting stuff really increases the solidness of what I've learnt, it sticks, no forgetting it two weeks later.

    Right now I'm constructing a tut about URL segments. However, because the page tree most of the time matches the natural URLs for a site, I'm finding it tricky to even find a use case!

    • Like 2
  11. On 18/09/2017 at 10:07 PM, abdus said:

    One handy tool when using urlSegments is to hook into Page::path and modify $event->return, so you won't have to manually building urls everywhere you need. You still need to implement urlSegment logic though, changing Page::path is a passive operation, it doesnt change routing behavior

    I know this an old thread, but can this be explained a bit more. I'm writing a tutorial about URL segments and this could be useful. I ask this because I can foresee the manual building of URLs to demonstrate how URL segments work. Although this would suffice for the tutorial, I'm curious about this hook as I'm getting more into PW now.

  12. I've only just noticed but I have a rather serious problem in that my webform cuts off the message text. Not sure why this is happening so any fresh eyes to look at this would be appreciated! contact.php:

    <?php namespace ProcessWire;
    
    wireIncludeFile("./vendor/vlucas/valitron/src/Valitron/Validator.php");
    $captcha = $modules->get("MarkupGoogleRecaptcha");
    
    $contactPageID = "1022";
    $contactFormRecipient = "MY_EMAIL";
    
    $name = $sanitizer->text($input->post->name);
    $email = $sanitizer->email($input->post->email);
    $message = $sanitizer->text($input->post->message);
    
    $v = new \Valitron\Validator(array(
        "name" => $name,
        "email" => $email,
        "message" => $message
        )
    );
    
    $v->rule("required", ["name", "email", "message"]);
    $v->rule("email", "email");
    
    if ($input->post->sendMe) {
        if ($v->validate()) {
            if ($captcha->verifyResponse() === true) {
    
                $message = "
                    <html>
                        <body>
                            <p><b>Customer name:</b> {$name}</p>
                            <p><b>Customer email:</b> {$email}</p>
                            <p><b>Customer message:</b></p>
                            <p>{$message}</p>
                        </body>
                    </html>
                    ";
    
                $mail = wireMail();
    
                $mail->to($contactFormRecipient)
                ->from($email, $name)
                ->subject('Website form submission')
                ->bodyHTML($message);
    
                if ($mail->send()) {
                    $session->flashMessage = "Thanks for your message! I will get back to you shortly.";
                    $session->sent = true;
                    $session->redirect($pages->get($contactPageID)->url);
                }
                else {
                    $session->flashMessage = "Sorry, an error occured. Please try again.";
                }
    
            }
            else {
                $session->flashMessage = 'Recaptcha must be complete.';
            }
        }
        else {
            $session->flashMessage = 'Please fill out the fields correctly.';
        }
    }
    ?>
    
    <div id="form-top" class="mb-5"></div>
    
    <div class="container">
      <div class="row justify-content-center py-5">
        <div class="col-md-10">
    
                <?php if($session->flashMessage):?>
                    <div class="alert <?php echo $session->sent ? 'alert-success' : 'alert-danger'?>" role="alert">
                        <?php echo $session->flashMessage;?>
                    </div>
                    <?php endif;?>
    
                    <form id="contact-form" method="post" action="#form-top">
    
    
                    <div class="row">
                        <div class="form-group col-sm-12 col-lg-6 py-2 <?php echo $v->errors('name') ? 'has-danger' : ''?>">
                            <label for="name">Name (required)</label>
                            <input class="form-control" name="name" id="name" type="text" value="<?php if ($name) echo $name; ?>">
                        </div>
    
                        <div class="form-group col-sm-12 col-lg-6 py-2 <?php echo $v->errors('email') ? 'has-danger' : ''?>">
                            <label for="email">Email (required)</label>
                            <input class="form-control" name="email" id="email" type="text" value="<?php if ($email) echo $email; ?>">
                        </div>
                    </div>
    
    
                    <div class="form-group py-2 <?php echo $v->errors('message') ? 'has-danger' : ''?>">
                        <label for="message">Message (required)</label>
                        <textarea class="form-control" name="message" id="message" rows="8"><?php if ($message) echo $message; ?></textarea>
                    </div>
    
                    <div>
                        <label for="recaptcha">Recaptcha (required)</label>
                        <!-- Google Recaptcha code START -->
                        <?php echo $captcha->render(); ?>
                        <!-- Google Recaptcha code END -->
                    </div>
    
                    <div class="form-group">
                        <button type="submit" class="btn outlined" name="sendMe" value="1">Enquire now!</button>
                    </div>
    
                    </form>
    
        </div>
      </div>
    </div>
    
    <?php
        $session->remove('flashMessage');
        $session->sent = false;
        echo $captcha->getScript();
    ?>

    If I submit:

    Quote

    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laudantium eum nemo excepturi obcaecati dolorem, maiores vel assumenda quibusdam beatae, adipisci laboriosam ipsum rem temporibus est reiciendis nesciunt alias fuga? Accusantium quaerat natus delectus rem illo repudiandae, repellat esse aliquid reprehenderit aspernatur mollitia molestias, quisquam sit error. Consequatur, dolores, quibusdam facere officia eveniet, cumque, doloribus voluptate eligendi facilis ut quam corporis! In eligendi rerum, qui quidem nulla distinctio adipisci et nobis tenetur aut nisi. Asperiores quibusdam itaque laudantium explicabo accusantium? Nihil laborum voluptatem ea mollitia possimus consequatur quo repellat culpa, ipsum tempore earum. Corrupti saepe explicabo veritatis repellendus vero perferendis odit.

    The form emails this:

    Quote

    Customer name: Sam

    Customer email: sam@testing.com

    Customer message:

    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laudantium eum nemo excepturi obcaecati dolorem, maiores vel assumenda quibusdam beatae, adipisci laboriosam ipsum rem temporibus est reiciendis nesciunt alias fuga? Accusantium quaerat natus delec

    Any ideas why this would be happening? Thanks.

    += EDIT ==

    Removing the sanitizer 'fixed' it.

    $name = $sanitizer->text($input->post->name);
    $email = $sanitizer->email($input->post->email);
    // $message = $sanitizer->text($input->post->message); <<< fail
    $message = $input->post->message; // works but not sanitized, bad!

    If I read here: https://processwire.com/api/variables/sanitizer/

    Quote

    Sanitize a single line of input text. Removes tags, removes newline characters, and truncates length to 1024 characters. This is multibyte safe if your PHP has multibyte support.

    Which is a suitable sanitizer for this field? This one?

    http://cheatsheet.processwire.com/sanitizer/properties-and-methods/sanitizer-textarea-value/

×
×
  • Create New...