Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 01/06/2013 in all areas

  1. I just released a new module: Trashman. It adds new admin page which allows users without superuser role to view and restore pages. Grab it while it's hot: https://github.com/apeisa/Trashman Few screenshots:
    10 points
  2. Welcome Nicole. I had a look at your module and there's quite some things missing. I'm with Pete that for what you want to create there isn't the need for a new fieldtype. But I'm not sure what exactly you're trying to achieve that you have come up with this approach, what is the goal? Just to explain a little about fieldtypes/inputfields. A fieldtype always needs an inputfield associated. The inputfield is then used as the "interface" to input values. The inputfields all have a render() method that will output markup in the editpage screen at the end. Also there's a database schema you should specify and also wakeupValue, sleepValue, sanitizeValue, formatValue and getBlankValue. So you can guess it's much more sophisticated and complex than you initially thought and you're mixing a lot of thing up that makes it hard to start with. Other "normal" WireData modules that hook into something or process modules that can create custom admin pages functionality are much simpler to start with. Also the getConfigInputfields() is to have settings for your module and not for something you went here. You could use it to globally define the two values of course, but it will only be available to superusers to edit it. Solutions To get back to what you want to acheive. I think Pete is right, but I think you don't want to create a front-end form? A good solution to have this on a page to configure, simply use two fields to have a integer (or range slider) and a page field to select the parent page. Basicly what you wanted to do with your module. Then you can use them in the template code to output the list. You can attach those two field to whatever template/page you want, maybe the home page or some other pseudo "settings" page you create. A code in the template then maybe looks like this: "parent_page" being the page select, "limit" being the integer field $settings = $pages->get("/settings/"); $results = $this->$pages->find("parent=$settings->parent_page, limit=$settings->limit, sort=-date"); echo "<ul class='$class'>"; foreach($results as $result) { echo "<li><h3><a href='{$result->url}'>{$result->title}</a></h3><p>{$result->summary}</p></li>"; } echo "</ul>"; For such a small thing it isn't really needed to have a module that renders that but you could create a helper function to include in your templates, or if you really want to start with modules, I think the following might be simpler to start with. Look at HelloWorld.module aslo to learn more. This is a module you can load and use its methods to call in templates. <?php class MyBlog extends WireData implements Module{ public static function getModuleInfo() { return array( 'title' => 'Blog', 'summary' => 'Displays a Page List', 'version' => 1, 'author' => 'Nicole Bardales', 'href' => '', 'singular' => true, 'autoload' => false ); } public function init() { // attach hooks maybe, not needed here } public function blogPageList($limit = 10, $parent = null) { $class = "page-list"; /* or you could retrieve the setting from a fixed page */ //$limit = $this->pages->get("/settings/")->limit; //$parent = $this->pages->get("/settings/")->parent_page; if(!$parent) return "Specify a parent int he second argument"; $results = $this->$pages->find("parent=$parent, limit=$limit, sort=-date"); if(!count($results)) return "No pages found"; $out = "<ul class='$class'>"; foreach($results as $result) { $out .= "<li><h3><a href='{$result->url}'>{$result->title}</a></h3><p>{$result->summary}</p></li>"; } return $out . "</ul>"; } } With this you can load the module in your templates and use the method it adds to output the list. // load module, since we made it non autoload $blog = $modules->get("MyBlog"); $parent = $pages->get("/blogposts/"); echo $blog->blogPageList(10, $parent); or // load module, since we made it non autoload $blog = $modules->get("MyBlog"); $parent = $pages->get("/settings/")->parent_page; $limit = $pages->get("/settings/")->limit; echo $blog->blogPageList($limit, $parent);
    5 points
  3. ProcessWire Skyscrapers Site Profile This is the profile for the skyscrapers demo site as seen at: http://processwire.com/skyscrapers/. This site profile release also coincides with some upgrades to the Skyscrapers site. The updates were to re-do many of the template files to make them easier to read, convert some classes to functions (easier for folks to understand), and convert the maps to use the FieldtypeMapMarker module. The main differences from the live site are that this profile excludes most of the photos and skyscraper text. Only the photos taken by me are included. This is to ensure we aren’t distributing any text or photos in case the license ever changes to something other than Wikimedia Commons. I can change the text/photos on my skyscrapers site, but can’t on any sites someone else sets up with this profile, so figure it’s better to play it safe. Requirements ProcessWire 2.3 OR ProcessWire 2.2 dev branch (2.2.12 or newer) ZIP How to install Get the latest version of ProcessWire 2.3. At the time this text was written, ProcessWire 2.3 wasn’t yet released, so if that is still the case you’ll want to get version 2.2.12 or newer from the dev branch. Before running the installer, replace all the files/directories in the /site-default/ directory of ProcessWire with those from this site profile. This includes the following: /site-default/config.php /site-default/install/ /site-default/modules/ /site-default/templates/ [*]Now run the installer to complete the installation. Template details The template files in the profile take the approach of populating variables that are output within a main/shared markup file. This is different from the basic profile that ProcessWire comes with. Specifically, make note of the following files: /site/templates/_init.php – This file is automatically included before any template file is executed. We use it to initialize the variables we populate and include a shared library of functions. /site/templates/_out.php – This file is automatically included after any template file is executed. In our case, we use it to contain our main markup that also outputs the variables we populated. /site/templates/includes/functions.php – This is where we are keeping a shared library of functions, most for generating skyscraper list markup. /site/templates/*.php – These are the site’s template files, each named consistently with the page(s) they represent. The primary focus of these files is to populate the $content variable that is output by _out.php. The use of _init.php and _out.php are something new to ProcessWire 2.3. These are specified in the /site/config.php: $config->prependTemplateFile = '_init.php'; $config->appendTemplateFile = '_out.php'; Use of this new feature is optional. We’ve used it in this profile because it reduces the amount of redundant include() code necessary in each of our template files. Download Skyscrapers Profile at GitHub or download ZIP file Skyscrapers Profile at modules.processwire.com Remember that you must have ProcessWire 2.3 (or 2.2.12 dev branch) or newer to install this profile.
    4 points
  4. Hello there, well, it's my first time working with ProcessWire and I simply love it - I've used Joomla, Wordpress, Drupal, WolfCMS and Typo3 before but somehow ProcessWire was the perfect choice for that kind of page. So I decided to rebuild the website of my Goju Karate club here in Germany. It's not responsive or anything special but I just wanted to present it. There's still some work to do (fix the background image on the right for lower resolutions), but basically it should look OK on 1280+ resolutions. http://www.esv-karate.de Long time since my last private web project. I also have to say that I'm not a professional web designer. In work life I'm a web developer (Oracle) so don't be shocked if you don't see anything innovative . Regards Seuche
    3 points
  5. Edit 2013-01-09: This module is deprecated - see the next gen version here: http://processwire.com/talk/topic/2515-module-aftersaveactions/ - - - After following the discussion on multiple save buttons and default action after page save I decided to give it a try. The result (or an early version of it to beat Soma ) is a module called PageEditRedirects. The module, inspired by this post in particular (and another module by adamkiss), adds four options to choose from when saving a page: stay in editor (default) go to the page list add a new sibling page view the edited page The options are always collapsed and the chosen option is saved into a cookie so that each user's preference will be remembered. Probably should add a checkbox "Remember this setting" (unchecked by default) so that a one-time use of another option doesn't get sticky. Module can be downloaded from https://github.com/n...geEditRedirects and wont be available from the modules directory just yet (because of the required PW 2.3). So, consider the module just an alpha version or a proof of concept as it hasn't been tested nearly at all (need to check it doesn't break Antti's Adminbar for example). Edits: * Added link to an early post on the subject. * Added a little more explanation on what the module does and doesn't do. * Removed the note on needed core changes (Ryan did those already).
    2 points
  6. Yeah, I noticed while trying the prependTemplateFile with LanguageLocalizedURL module. I found a solution to avoid the issue and also the double render issue it had before with render method. I commited an update to 0.1.1 and will update the module thread later.
    2 points
  7. I love studying these. And of course I had my own init stuff going on with functions and variables, so I wondered what others were doing about that. Thanks Ryan!
    2 points
  8. FieldtypeMapMarker Module for ProcessWire 2.1+ This Fieldtype for ProcessWire 2.1+ holds an address or location name, and automatically geocodes the address to latitude/longitude using Google Maps API. This Fieldtype was also created to serve as an example of creating a custom Fieldtype and Inputfield that contains multiple pieces of data. Download at: https://github.com/r...ldtypeMapMarker How to Use To use, install FieldtypeMapMarker like you would any other module (install instructions: http://processwire.c...wnload/modules/). Then create a new field that uses it. Add that field to a template and edit a page using that template. Enter an address, place or location of any sort into the 'Address' field and hit Save. For example, Google Maps will geocode any of these: 125 E. Court Square, Decatur, GA 30030 Atlanta, GA Disney World The address will be converted into latitude/longitude coordinates when you save the page. The field will also show a map of the location once it has the coordinates. On the front end, you can utilize this data for your own Google Maps (or anything else that you might need latitude/longitude for). Lets assume that your field is called 'marker'. Here is how you would access the components of it from the API: <?php echo $page->marker->address; // outputs the address you entered echo $page->marker->lat; // outputs the latitude echo $page->marker->lng; // outputs the longitude Of course, this Fieldtype works without it's Inputfield too. To geocode an address from the API, all you need to do is set or change the 'address' component of your field, i.e. <?php $page->marker->address = 'Disney Land'; $page->save(); // lat/lng will now be updated to Disney Land's lat/lng
    1 point
  9. ProcessDateArchiver ProcessWire Date Archiver Process Automatically archives pages based on a Datetime field (e.g. /news/2013/01/03/some-news-item/). Behavior - When you add a page with a specified template, the module will automatically create year/month/day archives for it. - When you change the date in a specified Datetime field, the page is automatically moved to the correct year/month/day archive. - When moving or trashing a page, the module will automatically clean up empty year, month and day archives. How to create an archiving rule 1. Go to the Setup -> Date Archiver screen in the ProcessWire admin. 2. Click on Add New Archiving Rule. 3. Specify the template that should be archived (typically the news-item template). 4. Specify the Datetime field that should be used to determine the date to archive by. 5. Specify the template that should be used for creating year archives. 6. Optionally specify the template that should be used for creating month archives. 7. Optionally specify the template that should be used for creating day archives. 8. Click Add Rule. Tips and tricks - Configure the archive templates that will contain other archives to sort its children by name. - Configure the archive template that will contain the news items to sort its children by the specified Datetime field. - You will improve usability if you dont allow the user to create date archives manually. How to Install 1. Install the module by placing ProcessDateArchiver.module in /site/modules/. 2. Check for new modules on the Modules screen in the ProcessWire admin. 3. Click Install for the Date Archiver Process. Module download: https://github.com/u...hive/master.zip Module project: https://github.com/u...ssDateArchiver/
    1 point
  10. Just for a bit of fun: Before ProcessWire After ProcessWire I was going to be mean and pick on other CMS', but this is fun just on it's own. Post your examples!
    1 point
  11. Hey all, I think it would be nice if the MarkupCache module could automatically expire specific caches when specific templates or pages are saved. This would allow us to cache heavy parts of a page for a very long time (or forever), and it'll only need to re-create the heavy part if its content has changed. It would also make sure no out-of-date content is shown. Advantages over the normal page cache are: - The normal page cache needs to re-render the whole page, this only needs to re-render the part that has changed (performance). - The normal page cache does not work with CSRF forms. I've coded a little proof-of-concept and I would like to hear if you guys have any suggestions or improvements. It works as following: Say you want to cache a news slider on the homepage: <?php if ( ! $data = $cache->get("HomeNewsSlider", 604800)) { // ... generate markup which uses the news-item template in $data ... $cache->save($data); } echo $data; ?> Then u would somehow configure the MarkupCache to expire the "HomeNewsSlider" cache when a page has been saved with the "news-item" template: This is how I have implemented it at the moment, but maybe someone has a better idea? I've also added a more convenient method (the begin() and end() methods) for caching markup: <?php if ($cache->begin("HomeNewsSlider", 604800)): ?> <h1><?=$page->title?></h1> // ... some other markup ... <?php $cache->end(); endif; ?> The module will start buffering the output when calling begin() and it'll save the buffer to the cache when calling end(). If the cache is available the begin() method will output the cached data. This way you wouldn't need to render all output to a $data variable. Hope u guys have some feedback or other/better ideas MarkupCache.module
    1 point
  12. I'm a Toronto-based web designer and developer. Tinacious Design is my ProcessWire-powered website and it includes my web design and development portfolio and information about my services. See the website here: TinaciousDesign.com The back-end uses a modified version of the Moderna admin theme. I also posted a video on Vimeo showing the behind-the-scenes process of adding a new portfolio item.
    1 point
  13. No problem - if something seems too hard in ProcessWire there's usually an easier way
    1 point
  14. @Pete and @Soma thanks for bearing with me. I realize that's similar to something you shared before Soma, an idea struck me but I guess I'm not getting anywhere with it. Yes Pete, you got it right, the code is outputted on the front-end and it does look like that, and yes Soma, they don't need to deal with the code since I'm the one outputting it. I guess I made PW difficult even though it's easy -- I just remembered something I read on PW: "Forget all that clutter you're used to dealing with in other CMSs"...
    1 point
  15. @nik, perhaps Pete can add a "love this" button
    1 point
  16. @Soma: I've got nothing to add or otherwise contribute here, but just wanted to say what an impressive explanation you've come up with! Good job as always - this time it just felt like a simple 'like' isn't enough.
    1 point
  17. This should be possible. You'd use a Pages::saveReady hook. You'll want to have your hook do something along these lines: if($page->template == 'album' && $page->isChanged('images')) { $newItems = $page->images->getItemsAdded(); if(count($newItems)) { // images were added, create your new unpublished blog post // the $newItems WireArray contains the images that were added } }
    1 point
  18. Thanks Pete, I'm happy if someone corrects me if it's vital. I just wanted to add another possiblity. You can also use the /site/config.php to add configuration you need throughout your site. Add this to the config file. $config->blogPageListLimit = 10; $config->blogPageListParentId = 1004; And you can use it wherever you need it. $pages->get($config->blogPageListParentId)->children("limit=$config->blogPageListLimit, sort=-date");
    1 point
  19. See a lot of changes already in 2.3. I'll love it. So far, I don't see issues. Sites i'm building now start with the 2.3 branche, cause I have lots of trust in all the work you've done. And I thank Soma, Nik, Teppo and all the others who contribute to make such a great product. Hope there's wil be a list of all changes there are when 2.3 is final.
    1 point
  20. I like this module, but I think I'd prefer it if it was a dropdown box right next to the Save button (I know, you can never please everyone). I'm sure it's been discussed before, but this works exceptionally well in MODx: It could look like this: [save] and [continue editing] - remember this option? [x] Then maybe the only other suggestion I have would be to set two options in the module config to select for it to appear next to the Save button at the top or bottom. This is also something I'd vote for making its way into the core as it is so useful and I don't think that it adds confusion if the language for the options is clear (which it is).
    1 point
  21. Finally figured this one out. Apparently PHP 5.4 comes with a class name "SessionHandler" that is the same as ProcessWire's. So I just renamed ours to be WireSessionHandler and now all seems good with PHP 5.4. But this is yet more motivation to move everything to namespaces sooner rather than later. Now thinking this has to be done in ProcessWire 2.4.
    1 point
  22. Greetings Ryan, Since it's not possible to "multi-like" a post, I'll just unofficially add them here... Like Like Like Like Like Like Like Like Like Like Like Like I've been waiting for the Skyscraper profile to be available for the newest version ProcessWire. There is a lot in that profile that is extremely valuable. Thank you again for all your amazing work. Matthew
    1 point
  23. The reason I like these kind of snippets so much is the freedom they offer. If you want to show the dev page to anyone that is logged in, change the conditional to: if($user->name='guest') If you want to give a special url like domain.com/?version=dev change it to: if($input->get->version!='dev') with the url version you can also make all the links work wth sessions like this: if($input->get->version!='dev' OR $session->version != 'dev') and inside the else: $session->version = 'dev';
    1 point
  24. Looks gorgeous! But a quick question: I auto-translated the page to german and ... is this really russian blind text?
    1 point
  25. The forums have been re-ordered and re-categorised in what we hope is a more logical setup. The idea is that the first set of forums introduces new users to what's going on, shows off some sites that have been built in ProcessWire as well as what's on the horizon. The second set is all about support - the aim is that newcomers will be guided to the first three forums in their search for a solution to a particular problem before posting it in the General Support forum. The remaining forums in that section tend to fall under more advanced features and contain more advanced questions as a rule. The final set of forums is Off Topic. There is a new Dev Talk forum for non-ProcessWire-specific discussion which frees the Pub forum up a bit more for general chat. Hopefully that all makes sense - the topics in the Pub have been split where appropriate into the Dev Talk forum.
    1 point
  26. Erika needed a simple website to showcase the books that she designed. I think this is as simple as a book showcase can get http://diplom.erikagrafika.com/ There are lots of transparent PNGs to be shown at the same time (transparency because of the shadows and cut corners), to make them smaller I found an amazing tool http://pngquant.org/. No kidding, this tools can cut the size of a "saved for web" transparent PNG to half. I love how you can use it in a bunch of directories at the same time from the terminal, but if you only need it for a few pictures and don't want to mess around with the terminal, this online tool uses exactly the same process http://tinypng.org/. edit: I must have messed up the title, can someone entitled change it to "diplom.erikagrafika.com"?
    1 point
  27. ryan - this is an amazing module! I'm just using it on a website I'm building and it is spot on Just a note to others: I originally had a separate Address field, but you don't need that with this module. I wasn't sure how much you could customise the address input, but you can do whatever you like within reason. What I mean is Google is pretty forgiving - you can put things like "Somewhere over the rainbow, Rydal, Ambleside, LA22 9LX" then it will just take the parts of the address it understands and find the location from that which essentially allows you to begin the address however you like (useful if you want to put a specific brand name or other title in there at the beginning). What you can't then do of course is drag and drop the pin as the address changes again, but so far the pins have been spot on for me since they're using UK postcodes and I'm picking items in the wilderness for now. I've also been putting commas in so that when I output the address on the page it can do a new line in the address based on the commas.
    1 point
  28. Hi Nicole & welcome to the PW forums, I've not written any FieldType extensions yet but does making this change help?... public function ___getConfigInputfields(Field $field) { $inputfields = parent::___getConfigInputfields($field); ... // rest of this method's code as per your original getConfigInputfields() code.
    1 point
  29. 1 point
  30. Wow! Everything on that site is amazing - looks like it's a fun one to build too. Good work!
    1 point
  31. Ah, looks like I may have encountered this bug (identical error message) and didn't know it was a bug--I thought it might have been due to my using getRandom(). I'll upgrade the ProcessWire install and see if it helps.
    1 point
  32. Not sure what the issue might be here, but just wanted to post the different options for getting random items: getRandom() - With no arguments, returns 1 random item (unless the array is empty) getRandom(n) - Returns n random items, where n is greater than 1.
    1 point
  33. Great, thanks Ryan, I'm sure there will be many great concepts worth adopting in this profile. I'll have to take a look ASAP!
    1 point
  34. Before ProcessWire: After ProcessWire: Errm... wait, does that mean ProcessWire is the Precioussssssssssssss?
    1 point
  35. The latest Batman film was pretty awesome - there are some ridiculous bits in the plot as well as some predictable moments, but in this sort of film you let them slide (there's a man in a bat suit ). It's nicely set up for many more films, so I hope whoever follows Christopher Nolan as director for the next one does as good a job. A fairly brutal film is The Raid (the original version). Little plot, but you won't see better action sequences that look that realistically painful anywhere else. Those chaps are hard as nails. I'm quite looking forward to this in 2013, amongst others:
    1 point
  36. There are another 3,000+ posts since that graph so I think it's still following that upward curve
    1 point
  37. Let's try with a couple of pointers and such first. Take a look at site/modules/HelloWorld.module (included with default installation) for an example of an autoload module and hooking methods - example 1 is really close to what you need. As Ryan said, you're aiming for Pages::saveReady with your hook. See http://wiki.processw...Module_Creation for more details on creating modules. This information should be enough to make an autoload module of your own, and have some method there run every time a page is saved. Of course you also need a field for the total price. Create a new field and set its visibility to hidden. Save the field once first to see this option in input tab. Then just add it to your product template. Getting further, you'd probably want to do your magic only for pages with the product template. And sanitize the price and vat before any calculations. You can set fields for the page in your hook like this (and they get saved magically): $page->nameOfYourField = "this is the value"; Now just go and try to create the module. . . . And now that you've tried and got it actually working (right? ), you can see an example of a working module here: https://gist.github.com/4462130. This calculates the area of a box with given width and height on a page with certain template - sounds a bit familiar, doesn't it?
    1 point
  38. Hello there and welcome to the forum! This sounds mostly trivial. You can do most of that with simple ProcessWire templates - one for categories, another for products and third for articles. Depending on your needs (how you want them to show up and how many of them there will really be) products could be actual templates or just repeater items on category template. I wouldn't suggest using repeaters if you're going to need separate pages for each item or there are going to be a lot of them, but for something like ~10 items on each category where only place their info is shown is that category page they would be an easy solution. Articles could be slightly more complicated, again depending on your needs: you said they should work like a blog, which would suggest that they require comments also. For that purpose there's a built-in comments module though, so that shouldn't be too difficult either. About those admin features you've mentioned, I'd suggest that this content should be added and edited as regular ProcessWire pages. You could always add custom admin panel, but that doesn't really make much sense in most cases. Not to mention that it's a lot of work, the result of which rarely exceeds that what ProcessWire already has to offer
    1 point
  39. Really great video! Nice job. Thanks for making this. It is the best video demonstration I've seen of ProcessWire. Would you mind if I embedded this on our videos page? http://processwire.com/videos/
    1 point
  40. Have u ever worked with Wordpress? Try to implement custom fields, I bet u will end up crying like a little girl
    1 point
  41. While I'm not in the camp that wants my URLs to go outside my site structure, I can see that it's a need some may have. And you've brought up a very good solution here--we could accomplish this pretty easily. SEO would not be a problem because the module that would implement the solution would hook into the Page::path function to ensure that it's reflecting the alias rather than the original. It would also not be a stretch to have the module perform a 301 to the alias when the page is accessed at the original URL.
    1 point
  42. Not really answering your queston, but I just tested using the tab fields on the repeaters (I imagine it wouldn't work, but was curious) and this is what happens. Ryan, wouldn't be too difficult to move those tabs inside the correspondant repeater on the module, right? If not in php, maybe with js.
    1 point
  43. At the start of this new year I launched my new website: Didjee.nl (in Dutch only, sorry )
    1 point
  44. The ProcessWire 2.3 installer now lets you set the admin URL as part of the install process.
    1 point
  45. Thanks for your help Nik! I emptied the cache and just tried with uploading the files of 2.2.9 once again and now it works. Still not sure what it was, though, as all the files were there on first upload … Maybe Ryan has any hints.
    1 point
  46. Hi Everyone, Follow-up question: what's a good way to refer to the ProcessWire framework? Of course, the whole system is called ProcessWire. Just wondering if, for clarity's sake, we might refer to the framework (for example) as the "Wire Framework," or something like that. This might seem like a technicality, but my thinking is that it sends a message that there is a framework underlying the system. As ProcessWire gets discussed and blogged about more in the future, this distinction could help convey a degree of meaning to developers and designers who recognize such things. What's the "official" name? Thanks, Matthew
    1 point
  47. Regarding to the post onjegolders made, I made a little form to create new pages. I think from this point it would not be hard to add more functionality. <?php /** * Page template * */ include("./head.inc"); echo $page->body; $success_message = "<h3 class='success'>Saved</h3>"; $success = false; // we assume it and set to true if form sent $error = false; // set and sanitize our form field values $form = array( 'name' => $sanitizer->text($input->post->name), 'title' => $sanitizer->text($input->post->title) ); $required_fields = array( 'name' => $input->post->name, 'title' => $input->post->title ); // check if the form was submitted if($input->post->submit) { // determine if any fields were ommitted or didn't validate foreach($required_fields as $key => $value) { if( trim($value) == '' ) { $error_message = "<h3 class='error'>Please check that you have completed all the required fields.</h3>"; $error = true; } } // if no errors, create a new page if(!$error) { $p = new Page(); // create new page object $p->template = 'basic-page'; // set template $p->parent = wire('pages')->get('/about/'); // set the parent $p->name = $input->post->name; // give it a name used in the url for the page $p->title = $input->post->title; // set page title (not neccessary but recommended) $p->save(); //create the page // populate fields $p->summary = 'Variable here'; // Populate a field $p->body = 'Variable here'; //Populate a field $p->save(); //save the populated fields echo $success_message; echo 'id: '.$p->id.'<br/>'; echo 'path: '.$p->path; } } ?> <?php if(!$success) { ?> <?php if($error) { echo $error_message; } ?> <form action="./" method="post" id="submitform"> <fieldset> <label for="name">Name *</label> <input type="text" name="name" value="" value="<?php echo $user->name; ?>" autofocus required /> <label for="email">Title *</label> <input type="text" name="title" value="" required /> <input type="submit" name="submit" value="submit" /> </fieldset> </form> <?php } else { echo $success_message; // testing echo 'id: '.$p->id.'<br/>'; echo 'path: '.$p->path; ?> <?php } ?> <?php include("./foot.inc"); ?> works on my localhost.
    1 point
  48. Great tutorial Soma! This is the best summary of using PW's Inputfields that I've seen. I noticed you did $field->attr('id+name', 'email') so just wanted to explain what that is for those that may be unsure of the syntax. That syntax is basically saying to set the 'id' and 'name' attribute to have the 'email'. While every field needs a 'name' attribute (like in HTML) the 'id' attribute is optional… if you don't assign an id attribute, PW will make one up. If you intend to custom style a field with CSS or target it from javascript, then it's best to assign your own 'id' attribute. Otherwise, it doesn't matter. // this… $field->attr('id+name', 'email'); // …is the same as: $field->attr('id', 'email'); $field->attr('name', 'email'); // …as is this (direct reference): $field->id = 'email'; $field->name = 'email'; The advantage of using the attr() function over direct reference is that attr() can't ever collide with other Inputfield properties that might have the same name as a field attribute. It's basically your way of saying "this should definitely be an HTML attribute and not anything else." For recognized attributes like 'name' or 'value' it doesn't matter what syntax you use because an Inputfield already knows 'name' and 'value' are standard HTML attributes. But if you needed to add a custom attribute like "data-something", well then you'd definitely want to use the attr() method of setting. That attr() method should only be used for things that would actually be HTML attributes of the <input>, because they will literally end up there. So if you do an $field->attr('label', 'Hello'); you'll end up with an <input label='Hello'> in the markup, which is obviously not something that you want. That's why you assign a non-attribute property like 'label' or 'description' directly, like: $field->label = 'Something'; Last note about $attr() is that it can be used for both setting and getting attributes: $field->attr('value', 'something'); echo "The field's value is: " . $field->attr('value'); // same as: $field->value = 'something'; echo "The field's value is $field->value"; To extend your example, lets say that you wanted the 'email' and 'password' fields in a fieldset titled "About You". You would create the fieldset, and then add/append the fields to the $fieldset rather than the $form. Then you'd add the $fieldset to the $form: $fieldset = $modules->get('InputfieldFieldset'); $fieldset->label = 'About You'; $field = $modules->get("InputfieldEmail"); $field->label = "E-Mail"; $field->attr('id+name','email'); $field->required = 1; $fieldset->append($field); // append the field $field = $modules->get("InputfieldPassword"); $field->label = "Password"; $field->attr("id+name","pass"); $field->required = 1; $fieldset->append($field); $form->append($fieldset); Or lets say that you wanted those 'email' and 'password' fields to be each in their own column so that are next to each other horizontally rather than vertically. You would assign the 'columnWidth' property to both the email and password fields. In this case, we'd give them both a value of 50 to say that we want them to be a 50% width column: $field->columnWidth = 50; To jump out of tutorial mode and into idea mode: lately I've been thinking that PW should have a YAML to Inputfields conversion tool in the core (something that would be pretty easy to build), so that one could define a form like this: And create it like this (where $yaml is the string above above): $form = $modules->get('InputfieldForm'); $form->load($yaml); echo $form->render();
    1 point
  49. 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...