Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 08/08/2017 in all areas

  1. In a current project I am using a Repeater field to build a kind of pseudo-table, where each Repeater item is a row. Some of the rows are headers, and some have buttons that toggle corresponding checkbox fields in a hidden FormBuilder form. The problem was that when the Repeater items were collapsed I couldn't see which rows were headers and which contained buttons. I tried including the fields in the Repeater labels but it still didn't provide enough visual difference to be quickly recognisable. So I investigated how classes could be added to selected Repeater items in admin depending on the value of fields within the Repeater items. This is what I ended up with... In /site/ready.php // Add classes to selected service row Repeater items $this->addHookAfter('InputfieldFieldset::render', function(HookEvent $event) { /* @var $fieldset InputfieldFieldset */ $fieldset = $event->object; $attr = $fieldset->wrapAttr(); // Fieldsets in a Repeater inputfield have a data-page attribute if(isset($attr['data-page'])) { // Get the Repeater item $p = $this->pages((int) $attr['data-page']); // Check field values and add classes accordingly // If item is a header if($p->row_type && $p->row_type->id == 2) { $fieldset->addClass('header-row'); } // If item has a checkbox button if($p->fb_field) { $fieldset->addClass('has-checkbox'); } } }); In admin-custom.css (via AdminCustomFiles) /* Special repeater rows */ .Inputfield_service_rows .header-row > label { background:#29a5aa !important; } .Inputfield_service_rows .has-checkbox > label .InputfieldRepeaterItemLabel:before { font-family:'FontAwesome'; color:#73cc31; content:"\f058"; display:inline-block; margin-right:6px; } Result
    7 points
  2. I do not want to grumble at all, and I hope my positive criticism will not be misunderstood but I would like to point out that ProcessWire's development road is a bit ad hoc these days. Do not get me wrong, I like it when Ryan needs some features and surprises us with stuffing them into the core, but this method of pushing the system further is still missing a crucial step: discussing the features to be implemented/refactored by the developer community. Also, we have a long list of feature requests but no one knows how and when they will make their way into the system if ever. They just seem to be forgotten. Only one example: Changelog support with 890 views and 11 likes possibly hits the 30% threshold set by Ryan but it is still waiting to be picked up. And there are many others as well, also at Github.
    7 points
  3. I'd love to know which module was causing the problem
    4 points
  4. Here is the post with the Lister Mode screenshots: https://processwire.com/talk/topic/6102-batch-child-editor/?do=findComment&comment=100763 You can set it up to edit any/all fields using the Lister interface. The only problem is that it doesn't allow for adding new items/child pages. Maybe what we actually need is to modify the repeater field to allow it to store pages under a specified parent within the page tree, rather than under Admin > Repeaters
    4 points
  5. There are some good reads in the forum too :
    4 points
  6. Just a couple of observations. It really doesn't 'hurt' anything to have high numbers of pages - they are only database rows after all (slight oversimplification). It might feel wrong or clumsy coming from other CMSs, but PW is more flexible. As far as a selector for recent news items, bear in mind that you can pass any string that can be parsed by strtotime() to a date selector so something like $latestNews = $pages->find("template=mini_news,created>='-18 hours'"); will return a pageArray of all items created in the last 18 hours, which you can manipulate further if necessary. The advantage of using a 'real' page for things like this is that you have all the flexibility that comes with that.
    4 points
  7. I recently needed a module that automatically fills the title field of a page using fields on that page. I couldn't see one that already existed so I made my own. This is mostly based on ProcessSetupPageName by @kixe which I use along with this module. Keep in mind I am very new to ProcessWire so perhaps somebody else can contribute or make a better one Note: The title is automatically hidden when using this module You can enter any string. To add a fieldname, subfield or property, you surround the fieldname with {}. Dot syntax allowed. Example: Fish: {parent.title} {myfield} https://github.com/nextgensparx/AutoPageTitles
    3 points
  8. That approach sounds good to me - very flexible. The only dedicated user hook is: Users::saveReady so you might need to add some logic if you don't want existing users altered when their details are changed. Regarding finding appropriate hooks, take a look at the Captain Hook panel in Tracy: https://processwire.com/blog/posts/introducing-tracy-debugger/#captain-hook-panel It makes it easy to search through classes and methods for things you might need and if you have the editor link protocol set up properly, it will open the file to the class/method you click on.
    3 points
  9. An approach you can use is to create a Page field referencing pages with that template. Add this field to the User template. Thus, if you add property X to the user "Mary", you can check that in your code when Mary requests page X.
    3 points
  10. Hi @szabesz! Yes, it works! I'm running it on PW 3.0.57 right now, in production. I have two actions: 1 - "Generate Short URL on adding a page" - On page save, it calls an API on another server (mine too) that runs an installation of https://yourls.org 2 - "Set end date on events, if empty" - the name is self explanatory.
    3 points
  11. This is a status update regarding the 4 modules: 1) JquerySelectize This module is not be required by any of the modules below, for PW versions > 3.0.66. Latest version also allows the module css/js to be loaded instead of the core css/js - mostly for testing/debug. 2) InputfieldSelectize (and InputfieldSelectizeMultiple) Everything seems to be working fine. The dependency on the JquerySelectize is removed for versions > 3.0.66, and the module inits the core library when in use. If JquerySelectize module is present/installed, then it will hand off the loading of the assets to the module, where you can then choose where to load from. 3) SelectizeImageTags UPDATE - latest version should work now - if you use this module with any PW version > 3.0.66, please update to the latest version. 4) SelectizeTemplateFields This works fine with the core selectize. The dependency on the jQuery module is removed for versions > 3.0.66.
    3 points
  12. The new core implementation of image tags seems to definitely not be compatible with the module, at least from my initial testing; 1) the first problem is that the core image tags do now allow for key/value pairs, where for example you can have a tag be something that is used by the api, like 'gallery' and the visible tag value be something easier to understand, like "Gallery: use this to group images into a gallery". I was using key/value tags a lot on some sites and now won't be able to upgrade to latest version until something is resolved. Forget this, i have worked on the module and it will just prevent the core js function from initializing the field and turn that init over to the module, when this module is in use. 2) the 2nd problem is that the core implementation still does not allow for different tags to be specified for context, and this is going to be critical; if you are using 1 images field across the site, but need to have different selectable tags based on which template that images field is on, then the tagging feature needs to be context enabled per template, as @ryan mentioned he would implement above. This would still be nice/useful. 3) in the event that the core implementation is not going to support both template context for selectable tags, as well as key/value for tags, then it would be great to allow my module to continue working for image fields. In order for that to happen, then there needs to be another option for the use Tags, here are the current options: Tags disabled User enters tags by text input User selects from list of predefined tags User selects from list of predefined tags + can input their own Here are the current identified problems with the existing options: 1. Tags disabled: If tags are disabled, it seems to clear some values from the database, even without saving the pages that the field is on; in my case i lost an entire website's worth of tags on images because i assumed that if i disabled tags here, that i could re-enable them and that the tags would still be there. This wrong assumption led to some hours of re-tagging an entire site worth of images. 2. User enters tags by text input : This 2nd option should probably read "User enters tags by text input (using Selectize)" Another option should be added below this: 2a. User enters tags by text input (legacy, free text field) This option would leave the inputfield free to be initialized by the module instead of the core. Forget it, this is all sorted now. -------- On a separate topic, Z-index issues remain a problem: these CSS rules fix the z-index problem: .InputfieldImageEdit__name { z-index: 2 !important; } .InputfieldImageEditAll .gridImage .ImageData { position: static !important; } Also, there is still an unresolved issue with something in the JS causing a conflict when an anchor tag is added to an option (which is frequently used on the InputfieldSelectize modules). Fixed now (somehow ?)
    3 points
  13. The post you linked to actually mentions two reasons why this might be bad: it could be identified as duplicate content and it could have a negative effect on crawl efficiency. Neither is something you should really worry about in this case, but then again: Google is a black box (it's impossible to say for sure how their algorithm works), that article is from 2010 (things have changed a lot since then), and some SEO experts do seem to love their micro-optimisations Although in that article they go on to say that their indexing process "often" automatically detects and corrects this issue, it is also true that this is one of those things that are so easy to fix that, even for a tiny theoretical chance that it could affect your rankings, you should stick with one URL format. According to various sources there's no penalty for duplicate content, especially not in cases like this. It would seem that the only way you can get penalised is if Google thinks you're trying to deceive them somehow with said duplicate content. I highly doubt that the trailing slash issue would count.
    3 points
  14. Hi guys, I want to share what I found working on my custom front-end email login: Even if no user were found for the submit email, Processwire should check for login because the login throttle api will be triggered and it will prevent multiple login tries. If the $session->login() is only called when the email owner is found, then the login throttle api will not be triggered and that tells requesters that a user with the email they try to login exists or not in your DB. /** * Login a user with the given name and password * * @param string $email * @param string $password * * @return bool|string * */ public static function signIn(string $email, string $password) { $signedIn = false; if(!empty($email) && !empty($password)) { // taken from ProcessLogin->execute(); if($email = wire("sanitizer")->email($email)) { $emailUser = wire("users")->get("email=$email"); $name = ""; if($emailUser->id) { $name = $emailUser->get("name"); } $password = substr($password, 0, 128); try { /** * even if the user is not found, try a login with a empty username * because the Processwire Login throttle API will be triggered and * prevent multiple login tries on the same email */ $result = wire("session")->login($name, $password); if($result instanceof User) { $signedIn = true; } } catch(\Exception $exception) { return $exception->getMessage(); } } } return $signedIn; } Look at pw_login_throttle_api_nessage.png for the message it will return if many tries are made. Thanks hope this help.
    3 points
  15. @Sipho - You can choose different templates for Repeater Matrix fields - that link I provided shows examples and states: But, as with repeaters, they are not pages with URLs that can be directly visited - you could probably "fake" this by using URL segments on the parent page and use the passed values to determine which repeater item to show. OT - I completely agree that the PageTable interface is not ideal - seems to me we need the repeater matrix editing interface for PageTable fields as well. When the PageTable field was added, repeaters didn't support ajax loading, hence the modal editing interface to ensure it was scalable with lots of items.
    3 points
  16. Users are pages so you have all the hookable methods in the Pages class too ('added', 'publishReady', etc). So you make the code in the hook conditional on the page template being 'user'.
    2 points
  17. I think @Sérgio Jardim's suggest may be the best solution... create a PageReference field 'property_permission' then add it to the user template so when a user is added the admin can set which pages they have access to... if ($user->property_permission->has("id=$page->id") || $user->property_permission->has("id=$page->parentID")) Thoughts? Also while anyone is here... can you hook into a new user creation? Preferably a hookAfter?
    2 points
  18. No need to remove "view" rights, just do a check at the top of your template file (or in an included file if you need this across your site) which checks the user and determines if they should be able to view the page. If not, then you could redirect them elsewhere. Does that make sense?
    2 points
  19. I don't really understand still - surely if the PDF script is generating errors that Tracy is reporting, you'd want to know, but maybe there is some weird interaction that is causing problems when there really isn't any. As for providing a way to switch off for some scripts, I just had a try at implementing something, but I don't think it's going to be possible because Tracy is loaded before anything else so that it can catch all errors, but this means that any variable you try to set from a script won't be available when it's time to enable Tracy or not. Does that make sense?
    2 points
  20. Thanks for the module, @Sipho! It also can be done using the approach described in this blog post: https://processwire.com/blog/posts/introducing-iftrunner-and-the-story-behind-it/#iftrunner-release This module has a broad, generic usage, so that's why you didn't find it when searched for you needs, I guess.
    2 points
  21. So, this isn't my favourite Music, but it is Music. At archiche.org you can download / listen to 25k+ 78rpm recordings like this one: https://archive.org/details/78_bugle-call-rag_metronome-all-star-band-pettis-meyers-schoebel-t.-mondello-b.-carter_gbia0011087a/Bugle+Call+Rag+-+Metronome+All+Star+Band.flac
    2 points
  22. Just tested this on a PW site I'm currently developing, and which is using default settings for slashes etc. Using Chrome extension Redirect Path to confirm, PW does indeed redirect @szabesz's example 2 (no trailing slash) above to example 1 (with trailing slash), with a 301. Hurrah!
    2 points
  23. @Sipho adrians BCE could also be an option for you. you can also include the lister as field in the page editor: @szabesz totally wrong it supports all fields - you just have to write your own return statement. that's what i was talking about: it's a little more effort to setup but it's a LOT more versatile. and it has column sorting and filtering onboard. also pagination of the results. for now it does only support ajax in one whole dataset. so tha pagination is done client side. that would have to be improved for large scale situations but it's totally doable. for example an image column would be as simple as this: Regarding the core-topic: I totally agree and i think it would be awesome if @ryan could take a look at my module and think about adding this to processwire. For me this has been an invaluable benefit in my last years projects... but it's still too incomplete for public use and would need some tweaking regarding support of mobile devices and - even more important - large scale.
    2 points
  24. just to show that this module can render any kind of field (seems that this was not clear enough: https://processwire.com/talk/topic/16929-choose-custom-repeater-template/?do=findComment&comment=148803 ) a simple column showing images: // pic $col = new dtCol; $col->name = "pic"; $col->title = 'pic'; $col->className = 'minwidth'; $col->data = function($page) { if(!$page->pics->count()) return ''; return $page->pics->each(function($img) { return "<img src='{$img->maxSize(200,200)->url}' alt=''><br>"; }); }; $t->cols->add($col); so you can do whatever you want and whatever the API + PHP can do... the module even supports a plugin-system where we can easily build cell-renderers that handle common tasks and make rendering even easier. this for example is the js file of the column filter that shows a filter input on top of each column: /** * this plugin creates filter inputs for every column * * #### usage #### * just set your table's settings: { colfilter: true } * * #### issues #### * the column filter breaks the table's column alignment on window resize * * #### roadmap #### * make it possible to have different kind of inputs like range sliders and dropdowns * */ /** * make sure that the tables searching setting is set to true */ $(document).on('beforeInit.rdt', '.RockDatatable', function(e, dt) { if(!dt.settings.colfilter) return; $table = $(dt.el); if(dt.settings.searching == false) console.log('overwriting setting "searching" to true for table ' + $table.attr('id')); dt.settings.searching = true; }); /** * add colfilter row to table header */ $(document).on('afterInit.rdt', '.RockDatatable', function(e, dt) { if(!dt.settings.colfilter) return; var $table = $(e.target); // table dom element var table = $table.DataTable(); var $thead = table.table().header(); // prepare the new header row var $tr = $("<tr role='row' class='colfilter' />"); $.each(dt.columnNames, function() { $tr.append($('<th><input type="text" class="colfilter"></th>')); }); // add it to the table header $tr.prependTo($thead); }); /** * handle filterinputs */ colfiltertimer = 0; $(document).on('keypress keyup change', 'input.colfilter', function(e) { var $input = $(this); var $tr = $input.closest('tr'); var $th = $input.closest('th'); // datatables splits the table in 2 divs when scrollX is used! thats why we need to find the table via the wrapper var table = $input.closest('.dataTables_wrapper').find('table.RockDatatable').DataTable(); var regex = false; // disable enter form submit var keyCode = e.keyCode || e.which; if (keyCode === 13) { e.preventDefault(); return false; } // delay search while typing clearTimeout(colfiltertimer); colfiltertimer = setTimeout(function() { table.columns($th.index()+':visIdx').search($input.val(), regex, false).draw(); }, 500); }); this may look complex in the beginning but once we have such a plugin we only have to set one option of the table and the filter inputs appear
    2 points
  25. The module got renamed and updated a bit as its not intended to run only on the backend, but work also on frontend side. - Now, the administrator can choose to activate or not the backend login buttons. - The providers are added "dynamically". You have to simply edit a JSON config file which once saved, will show the required fields in the module settings. For example the following JSON config will only provide Google as login provider : { "providers": { "google": { "className": "Google", "packageName": "league/oauth2-google", "helpUrl": "https://console.developers.google.com/apis/credentials" } } } Small note for pw users : If like me you did not know, there is another module that manages OAuth2 authentication. Feel free to use the one which suit your needs! more info there: @jmartsch you should create a new module thread
    2 points
  26. Ok, I got all that was needed for my design thanks to @fbg13 code for obtaining the user via the author id. I am attaching my complete code that shows the topic where the latest X-comments were added, shows the date of adding (based on the time format), shows the author of the comment and in my scenario shows the parent of the page (which in my case was used as category). On top of that it contains the anchors to the original comment so if clicked it would go straight to the content of the comment. To have the anchoring working, you need to assign the comment-## to the form (where ## is the ID of the comment). Thanks again to all who kindly shared their code that helped me get here.
    2 points
  27. Not sure if it could cause the issue, but in your copyParent() function you could try find() instead of findMany() - no need for findMany() when you have a limit of 50. Also, the selector you posted looks a bit off: $tx = wire('pages')->findMany("template=transaction-earn, start=$start, limit=$limit, sort=transactiondate, [tagreference=$tag, merchantreference=$merchant]"); What is going on with the section in the square brackets at the end? Looks a bit like a subselector but you are not matching it against a field.
    2 points
  28. This module helps you dynamically create schemas for improved SEO & SERP listings from within your templates. Each schema can be configured to meet your requirements. You can even add your own ProcessWire schema classes to the module. Read about the module on github: https://github.com/clipmagic/MarkupJsonLDSchema Download from github: https://github.com/clipmagic/MarkupJsonLDSchema/zipball/master Download from ProcessWire modules: http://modules.processwire.com/modules/markup-json-ldschema/
    1 point
  29. As fas as I know, currently there is no way for a module developer to include a changelog in a way that enables us to check out the changes in the admin before upgrading.
    1 point
  30. My apologies - yes, that's not what you want You still may choose to go with a "you don't have access" message, rather than a 404 - I guess it depends on your use case. Either way, sorry for the confusion
    1 point
  31. @Manaus Can you provide some example code? Unfortunately I do not understand what you mean by "no block is being passed". Is it possible you are mixing up features of the template engine with the module? In smarty, you use the {block} tags to define sections that are either inherited or overwritten in a child template. To overwrite a block, you must use {extends} in your child template. If you provide some code I'm sure I can help you Cheers
    1 point
  32. @adrian I will move it to my online host in a few hours and will share the login details. Thanks in advance to you and @fbg13 again for spotting my silly error.
    1 point
  33. Did you add a semicolon after the statement?
    1 point
  34. @szabesz: that seems pretty weird indeed. I guess it could have something to do with different timezone settings and such.. or not. For the time being I've updated the module to use the DATE_RSS constant instead of the 'r' date format for RSS feed dates, but as far as I can tell that should not make any actual difference. Just a precaution, really. Anyway, let me know if you figure out anything new
    1 point
  35. Have you tried looking into the matter with something like https://processwire.com/blog/posts/introducing-tracy-debugger/ ?
    1 point
  36. @bernhard To clarify, I basically want a PageTable but with the repeater matrix editing interface as @adrian said.
    1 point
  37. @szabesz I just want some simple AJAX editing for pages . I don't mind about column sorting as much as this. For now I will just continue using PageTables with modal editing, as inconvenient as it is. I would also join in the crowdfunding to push this forward @adrian I really wanted something that did make pages with actual URLs that can be visited. I don't really feel comfortable using Repeaters in that way. It's just not what they were designed for (I think).
    1 point
  38. You're setting the "name", but there isn't a "name" field, it's the "cite" field that you need to populate the new comment with. Maybe you could take a look at my old PR and update it for PW 3 and re-submit because it takes care of this without manually building/processing the comment submission form.
    1 point
  39. Is this what you are referring to: http://processwire.com/api/ref/fieldgroups/ Not sure why it isn't linked - must be missing from the API Explorer script that @ryan runs to generate the ref pages. There actually seems to be the opposite problem with: http://processwire.com/api/ref/wire-database-backup/ - that page 404s, but is linked to under Core Classes > WireDatabaseBackup in the dropdown.
    1 point
  40. Just an FYI - I have that setting on (as is default), and if I link to a page without the trailing slash, it always redirects to the slash version. Any chance you have something that might be hijacking the redirect?
    1 point
  41. Hello @Peter Knight, as long as you don't mix both versions in your internal links or XML sitemap, I don't think it is bad. Here is what Google writes to this topic: Or could you please explain a little further or provide an link, why it would be "obviously bad"? I am no SEO expert, so that would interest me. I have never changed the default setting for URLs and never experienced an downside from it. Also search engines maybe indexing both versions both show only the version with slash as results. Regards, Andreas Edit: I have missed, that your URLs do not redirect.
    1 point
  42. @szabesz: so far I've been unable to reproduce this issue or figure out it's source. The RSS feed should use the timestamp column from database, and that in turn should be the date of the edit (according to MySQL, as this column is automatically set to CURRENT_TIMESTAMP). Are you sure that this issue only shows up at the RSS feed and not the main Changelog view too?
    1 point
  43. @fbg13, you're a real hero! EDIT: Uh, I meant also @flydev, your code did the trick. Now it looks like it should look! Thanks! I think the space between the ' ' did the trick, I am not sure but I will spend this evening to figure out what I did wrong. I am building this module to make the process for handling RMA's in my company easier. So I am creating a module and $this->GeneralfieldsSelector grabs all the fields that are selected in the module settings to show them on the frontend. I didn't want to build the form itself because maybe I will also release this module here on PW and than is this a bit better than a custom made HTML-form XD
    1 point
  44. Looks like you need to use $input->url(true) to get the query string with it. But maybe you already tried that?
    1 point
  45. On the subject: https://blog.toggl.com/how-does-music-affect-work-infographic/
    1 point
  46. Because the page id isn't the key in the PageArray.
    1 point
  47. Since there are a lot of topics about the same theme, I decided to write a small module which overwrites the core function ___SetupPageName(). The module allows now to populate the page name using proprietary date() function. Works like PHP date() with follwing exceptions: Everything between the brackets is detected as format string, meaning no 2nd parameter possible. No need to use quotes around the format string. Spaces not allowed. from any page property, page field including subfields, parent property, parent field etc. Meaning everything what you get with $page->get(); including dot syntax. The function will give error and warnings in case of unproper settings, but creates the page with name 'untitled' anyway. Download here: http://modules.processwire.com/modules/process-setup-page-name/ Some Examples The following settings in parent template 'Name Format Children' will assign name immediately. date(Y) date('Y-m-d') parent.title parent.parent.title parent.id template.id assign name after page saving and/or population of depending field. Overwrites 'untitled' after all fields which are defined in parent template are populated. id (any other page property) pagefieldname, multiple pagefieldnames show a warning. pagefieldname (value not populated)show an error. date() // empty, no format assigned date(Y // missing closing bracket date(Y md) // unallowed space notexistingfieldname notexistingproperty existingfield.notexistingsubfield The function in the module ___SetupPageName() could be completely copied as is to the core class $pages. @Ryan Would be nice to see this in core. Related topics: https://processwire.com/talk/topic/8576-name-format-children/ https://processwire.com/talk/topic/8217-name-format-for-children-based-on-any-field-not-just-title/ https://processwire.com/talk/topic/11628-custom-page-name/ https://processwire.com/talk/topic/11349-page-add-step-not-being-skipped-when-name-format-for-children-is-set/ https://processwire.com/talk/topic/10701-automatic-page-name-using-processpageaddexecute-and-pagetable/ https://processwire.com/talk/topic/10208-pagetable-automatic-page-name-format-when-multiple-templates-allowed/ https://processwire.com/talk/topic/9979-name-format-for-children-for-multiple-allowed-templates-for-children/ https://processwire.com/api/modules/process-template/ Any recommandations after testing welcome. Download here: Download here: http://modules.processwire.com/modules/process-setup-page-name/ Edit: small enhancement to prevent display of warning twice. 23.12.15 multiple values possible now 24.12.15 made compatible with PW 3.x 27.12.15 Update Version 1.0.8 09.01.16 Update Version 1.1.0
    1 point
  48. Just added some new features and a couple of bug fixes to the dev branch. Fixes for export mode with certain complex field types Added support for AJAX loading of BCE - especially useful if you are using the "New Tab" position option - requires PW 2.6.11+. This will make Page -> Edit load much quicker when you have lots of child pages. New Lister mode - this allows you to view (and configure the default columns/filters) all children under the current page. If you have ListerPro installed you can also use the Actions on the children. This also supports inline editing which makes for a very quick and easy way to edit the key fields on each child page. Please let me know how the new AJAX load and Lister mode features work for you - I think I need some wider testing before pushing this to the master branch. You can define the Lister config settings sitewide, and then provide overrides for each parent page that has been enabled under "Configurable Pages" This screenshot shows the new Lister mode configured to show a predefined set of columns - a great way to preview the page content of child pages. This shows the Lister Inline Edit mode - making for very quick editing of key fields in child pages.
    1 point
  49. Hi Soma, Yes, female. I read that module and it seems complicated to me. I will read again to try to understand it. Thanks.
    1 point
  50. Ryan, Thanks this gave me a great place to start. I thought I'd share the version I created in case anyone finds it useful. • Single template for the login/logout. • Automatically redirects the user back to whatever page they originally requested after they login. ./includes/login.php <?php // Handle logouts if($input->get->logout == 1) { $session->logout(); $session->redirect($page->path); } // If they aren't logged in, then show the login form if(!$user->isLoggedin()){ // check for login before outputting markup if($input->post->user && $input->post->pass) { $user = $sanitizer->username($input->post->user); $pass = $input->post->pass; if($session->login($user, $pass)) { // login successful $session->redirect($page->path); } else { $session->login_error = 'Login Failed. Please try again, or use the forgot password link below.'; } } ?> <!DOCTYPE HTML> <html lang="en"> <head> <title>Custom PW Login</title> </head> <body> <form action='./' method='post'> <div class="login"> <? if($input->post->user && $input->post->pass) { echo "<p class='error'>" . $session->login_error . "</p>"; }?> <p><input type='text' id="user" name='user' placeholder='Username'/></p> <p><input type='password' id="pass" name='pass' placeholder="Password" /></p> <p><input type='submit' class="btn" name='submit' value='Login' /></p> </div> </form> </body> </html> <? die(); // don't go any further if not logged in } // end !logged in ?> In any template you wish to protect: <? require("./includes/login.php");?> To trigger a logout: <a href="?logout=1">Logout</a> Note: I'm using the HTML5 placeholder attribute. Browser support is not 100%. You may want to use labels instead, or use some jQuery (like I did) to add the placeholder text for browser that don't support it. SideNote: How do you get code indents to stick when posting? I'm having to go back and add spaces to each line. I use tabs when coding.
    1 point
×
×
  • Create New...