Jump to content

kongondo

PW-Moderators
  • Posts

    7,529
  • Joined

  • Last visited

  • Days Won

    160

Everything posted by kongondo

  1. I'm curious why this matters in the present circumstance?
  2. To be honest, although that thread shows you how you can use the PW API to create (read, the HTML) forms, 'a basic (or non-basic) PW form' does not exist; You need to create a HTML form and use ProcessWire to process that form. It is that simple. OK, back to crux of the matter; how to handle user registration from the frontend. There are several issues/steps here: How to create the form (simple; use a HTML form) Where to post that form (i.e., post to the page where the form is displayed, or post to another page) How to handle spam + cross-site forgery How to handle double registrations Feedback to the user once form has been submitted How to deal with errors/validation - client and server-side How to process the form inputs on the server-side (including sanitizing inputs) How and where to save form inputs How to send confirmation email Tackling above: Create Form: This is simple. Create your HTML form in a template file. I suggest using 'post' for method and action to post to self, i.e. './' Post destination: I've suggested posting to self, but you can use some other URL (i.e. an existing page). Spam: I suggest using a honeypot or double honeypot AND CSRF (see $session->csrf). Please Google this forums for examples. If I get time to do this I'll update this post. Double registrations: You would need to check submitted email against saved emails. User Feedback: Some people prefer to redirect to a different page with a thank you message, others reload the same page but don't show the form, just the thank you message. Up to you. If redirecting, see $session->redirect(). Errors + Validation: I suppose you know how to deal with client-side validation. Server-side, you will use $input->post; Use that to check if all required inputs sent; Use $sanitizer to sanitize inputs, e.g. $sanitize->email() for emails. Process Form: See #6. Save Guest: This depends on how you want to save guests. Do you have an external database? Then make use of $database. However, I would go for pages, whereby, each registration is a page, tucked away under some parent page. The title of the page could be the guest's full name and the email would be saved in an email field. This means a template with two fields; title and email. Confirmation Email: See WireMail. Sorry, it's getting late here and cannot give you specific examples. Hopefully the above will give you some food for thought. Happy to provide more details later if you get stuck. Others may chime in too, so, you should be alright :-). ps: If you will be dealing with forms a lot, I recommend investing in Form Builder.
  3. That's coming from ProcessWire's file compiler; it is not a bug on Blog's side. Try clearing your file compiler cache to see if it solves the issue.
  4. Maybe two options to consider: WireCache: Create a natural sort field, say nat_sort. Have this hidden; we don't need to see it in the admin. Add that to the template of the pages you need to sort naturally + paginate (let's call the template 'nat-sort-pages'). Create your Hook and add a function that will build/refresh a non-expiring Wire Cache every time a page that uses 'nat-sort-pages' template is created (no need to do this when the page is edited; just when added). The cache will save the new page's ID, Title (the field to naturally sort) and a 'nat_sort' value of 0 (or whatever your starting index is; here we also assume this is the first page created). Subsequently, when another page is added, your Hook will retrieve the cache, add the details of the new page to the array, use PHP natsort() to sort that array (by Title) + change the values of nat_sort within the array, save it back to the Wire Cache, then use SQL to insert the values in your nat_sort field. Your nat_sort field will be an integer field, so you SQL (pseudo code) will INSERT nat_sort_value IN nat_sort WHERE id=page->id. That should be a very fast operation. In the frontend, use a find sorted by your 'nat_sort' field (sort=nat_sort in the selector) to retrieve paginated results. getById() + SQL nat sort: This approach does not require a nat_sort field nor a Hook. It is an on-demand method for use in the frontend. Use a suitable SQL workaround to naturally sort a limited number of results (i.e. see links above + you'll need to use SQL LIMIT and START). Your SQL will only need to fetch the IDs of those pages. Then use getById (see example here) to retrieve those pages, which you then pass on to your pagination. Both approaches have their pros and cons, obviously.
  5. @Doc, please wrap your code in code blocks using the <> icon (7th from the left). Much easier to read that way, thanks.
  6. Depends on the scenario: If I want to retrieve a limited number of pages (with no requirements for pagination), then have those naturally sorted, I'd go for PHP. If I want paginated results, it means I need them to be already 'naturally-sorted' as they are retrieved, meaning, doing it at the database level, then I'd go for SQL. The present case: Using a Hook to amend the values of a group of pages every time a new page is created. If that group of pages is substantially huge, if using PHP, it means, first retrieving the whole group, sorting them naturally, then saving them. That in itself could be a big hit on the server (we are loading lots of Page objects in memory). Assuming pages are created at a high frequency, that further compounds the issue. In such cases, SQL will most likely be faster and use less memory.
  7. No, it is not possible out-of-the-box but there are workarounds: http://www.mysqltutorial.org/mysql-natural-sorting/ https://www.copterlabs.com/natural-sorting-in-mysql/ https://chrisjean.com/mysql-natural-sort-order-by-on-non-numeric-field-type/ If we are talking a potentially huge result set, I would consider a SQL solution (see links above) to update that field for each page in the result set.
  8. Welcome to the forums @TJB. You seem to have made that page's template a system template. You cannot delete system resources like that. You would need to do it using the API. An example here:
  9. Have a look at these discussions: Edit: Not sure will work for you actually, i.e. if you need a database level sort. @fbg13, I'm not sure that will produce desired results since that sort will take place in-memory, i.e. after the PageArray has been retrieved. I think @Jason Huck wants the sort to take place at database level.
  10. @mel47, Please see this note on how to call a menu in a multi-lingual environment: If that doesn't resolve your issue, try refreshing your file compiler cache.
  11. Hi @MaryMatlow, Same way, really. renderPosts() takes 3 arguments, the third of which is $options. Since you need to pass in the 3rd argument, in blog-post.php, line #56, you also have to specify the second argument like so: $options = array('post_comments'=>0); $content = $blog->renderPosts($page, false, $options) . $blog->postAuthor() . $renderComments . $blog->renderNextPrevPosts($page); The 'false' is the second argument. The post will be rendered in full since what that says is that $small = false.
  12. http://processwire.com/blog/posts/roadmap-2017/#whats-in-store-for-processwire-in-2017
  13. I'd say go for it! Not only do I wish you success in your endeavour, but I am hopeful that this will also give ProcessWire some good exposure .
  14. $pages->get() will always get you ONE page only. In your case, it gets you the first child of $store, i.e. Page A. This is because Page A, via sorting, comes first (i.e. before Page B and Page C. $pages->get() returns a Page. If you did a $pages->find(), this will always return several pages (if it found them, of course). The important thing, as noted earlier, is that $pages->find() returns a PageArray. That means, several Page Objects. So, you cannot directly echo like so: $results = $pages->find('template=basic-page'); // cannot do this; it doesn't make sense since you have multiple items inside $results //...so, you would need to loop through it using a foreach echo $results->title; Think of it this way: // FRUIT: this is very specific. You are requesting a banana; not an orange, not an apple, but a banana. //...We will get you a banana $fruit = $pages->get('banana');// @note: pseudo code! // hence, you can do echo $fruit->title;// outputs 'banana' // BUT....if you want FRUITS...there are several fruits... $fruits = $pages->find('fruits');// @note: pseudo code! // if you did this, the question would be, what fruit was that again? // direct 'echo' doesn't make sense; // ...you need to tell us what fruit you want; apple? orange? banana? There's several fruit in here! echo $fruits->title; // aaah, so, we loop through the basket, one fruit at a time... foreach($fruits as $fruit) echo $fruit->title;// this will output each fruit in here in turn...apple; orange, banana, etc... Hope this makes sense.
  15. Update: Menu Builder Version 0.1.7. Changelog Fixed a bug that caused titles of menu items with apostrophes not to display properly in menu settings. Thanks @LMD Code cleanup and refactoring.
  16. In the frontend, have you checked to see how many pages are being retrieved? Something like this: $prevEvents = $player->child("name='history'")->children("date>=$prevDate"); echo $prevEvents->count();// does this output the number of pages you are expecting? In addition, any repeaters in the fields you are retrieving?
  17. Seems you've been away for a while . That's what the file compiler is for. It allows version 2.x modules to run in version 3.x.
  18. What about an autoload module that will make the changes on save? This way, it's done once. Or maybe JavaScript to make changes client-side on click' insert-link'? Hmm, maybe not be as elegant though. Just some rumblings....
  19. I see what you mean. Meanwhile, maybe there are workarounds to accomplish what you are after. I have nothing concrete atm .
  20. How is that different from selecting a checkbox, one each for btn, btn-success and btn-sm? Works for me just fine. <a href="/blog/" class="btn btn-success btn-sm"></a>
  21. @MaryMatlow, Seems you missed the third link in my post above . The array indices were changed to 'post_image_tag' => 'whatever', etc..Please see the whole list there or within the module code itself
  22. Yeah, that's a lot of post . Let's see if we can take it bit by bit. I believe this line will grab ALL the children (a PageArray) of history from the database, then return the first (in-memory manipulation) of these retrieved results: $lastEvent = $player->child("name=history")->children("sort=-date")->first(); Instead, try this, to actually grab ONLY one child from the database: $lastEvent = $player->child('name=history')->child('sort=-date'); This line doesn't make sense to me: $prevEvents = $player->child("name='history'")->children("date>=$prevDate"); How can previous events' date be greater than the previous date?
  23. In a hurry, so a quick (and not thoroughly tested) part answer Actually, the 'normal' selector is an AND not an OR (i.e. the comma separated selector). 2a. Both terms in at least one field (@see docs) // both terms in at least one field $sel1 = '(title%=foo, title%=bar), (body%=foo, body%=bar)'; 2b. At least one term in at least one field (@see docs) // at least one term in at least one field $sel2 = 'title|body%=foo|bar'; 3 LIKE (@see docs). Here we use %. See the notes in the docs about the alternative + matching order, etc
  24. Seems like a CKEditor quirk. Rather than going to the source code, you can highlight the heading and change it to 'normal' before deleting it. Not ideal, I know...
×
×
  • Create New...