Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 06/14/2020 in all areas

  1. Just wanted to share what I recently used to create forms in modules and in frontend using the API and Inputfield modules PW provides and uses on its own. I think many newcomers or also advanced user aren't aware what is already possible in templates with some simple and flexible code. Learning this can greatly help in any aspect when you develop with PW. It's not as easy and powerful as FormBuilder but a great example of what can be archieved within PW. Really? Tell me more The output markup generated with something like echo $form->render(); will be a like the one you get with FormBuilder or admin forms in backend. It's what PW is made of. Now since 2.2.5~ somewhere, the "required" option is possible for all fields (previous not) and that makes it easier a lot for validation and also it renders inline errors already nicely (due to Ryan FormBuilder yah!). For example the Password inputfield already provides two field to confirm the password and will validate it. De- and encryption method also exists. Or you can also use columns width setting for a field, which was added not so long ago. Some fields like Asm MultiSelect would require to also include their css and js to work but haven't tried. Also file uploads isn't there, but maybe at some point there will be more options. It would be still possible to code your own uploader when the form is submitted. Validation? If you understand a little more how PW works with forms and inputfields you can simply add you own validation, do hooks and lots of magic with very easy code to read and maintain. You can also use the processInput($input->post) method of a form that PW uses itself to validate a form. So getting to see if there was any errors is simply checking for $form->getErrors();. Also the $form->processInput($input->post) will prevent CSRF attacks and the form will append a hidden field automaticly. It's also worth noting that processInput() will work also with an array (key=>value) of data it doesn't have to be the one from $input->post. Styling? It works well if you take your own CSS or just pick the inputfields.css from the templates-admin folder as a start. Also the CSS file from the wire/modules/InputfieldRadios module can be helpful to add. And that's it. It's not very hard to get it display nicely. Here an code example of a simple form. <?php $out = ''; // create a new form field (also field wrapper) $form = $modules->get("InputfieldForm"); $form->action = "./"; $form->method = "post"; $form->attr("id+name",'subscribe-form'); // create a text input $field = $modules->get("InputfieldText"); $field->label = "Name"; $field->attr('id+name','name'); $field->required = 1; $form->append($field); // append the field to the form // create email field $field = $modules->get("InputfieldEmail"); $field->label = "E-Mail"; $field->attr('id+name','email'); $field->required = 1; $form->append($field); // append the field // you get the idea $field = $modules->get("InputfieldPassword"); $field->label = "Passwort"; $field->attr("id+name","pass"); $field->required = 1; $form->append($field); // oh a submit button! $submit = $modules->get("InputfieldSubmit"); $submit->attr("value","Subscribe"); $submit->attr("id+name","submit"); $form->append($submit); // form was submitted so we process the form if($input->post->submit) { // user submitted the form, process it and check for errors $form->processInput($input->post); // here is a good point for extra/custom validation and manipulate fields $email = $form->get("email"); if($email && (strpos($email->value,'@hotmail') !== FALSE)){ // attach an error to the field // and it will get displayed along the field $email->error("Sorry we don't accept hotmail addresses for now."); } if($form->getErrors()) { // the form is processed and populated // but contains errors $out .= $form->render(); } else { // do with the form what you like, create and save it as page // or send emails. to get the values you can use // $email = $form->get("email")->value; // $name = $form->get("name")->value; // $pass = $form->get("pass")->value; // // to sanitize input // $name = $sanitizer->text($input->post->name); // $email = $sanitizer->email($form->get("email")->value); $out .= "<p>Thanks! Your submission was successful."; } } else { // render out form without processing $out .= $form->render(); } include("./head.inc"); echo $out; include("./foot.inc"); Here the code snippet as gist github: https://gist.github.com/4027908 Maybe there's something I'm not aware of yet, so if there something to still care about just let me know. Maybe some example of hooks could be appended here too. Thanks Edit March 2017: This code still works in PW2.8 and PW3.
    1 point
  2. Hi @michelangelo, what's about pagination? As you mentioned the skyscraper site, if I remember right, it also uses pagination. And besides pagination you should use caching. If possible, you should use ProCache. But there is also template caching and more available.
    1 point
  3. Definitely take a look at RockFinder3 along Rock2Tabulator.
    1 point
  4. Yeah, little bit of confusion on my side. I think it was too hot on this day. Moving to the dev branch.
    1 point
  5. I for one am excited to see the release of this; waiting patiently.
    1 point
  6. I've used Lazy Cron successfully elsewhere, combined with a Cron job to trigger it. However on my current project it is not working. The reason seems to be that it is not giving a normal response type. The Cron job is wget --quiet no-cache -O - https://domainname... It runs each time with an error-free response, but does not trigger Lazy Cron. If I paste the url https://domainname... into the browser it does trigger LazyCron. With a bit of debugging, the reason is clear - the Cron job gives responseTypeAjax = 2 which is bypassed by Lazy Cron, but the browser gives responseTypeNormal = 1 which is processed by Lazy Cron. Any ideas why and how to fix it (other than hacking LazyCron.module)? The triggered page is just a simple template with a response of "echo 'Hello from ' . $page->title;" EDIT: Please ignore this - I think I have mis-diagnosed the problem - will sleep on it!! EDIT2: Nothing wrong with LazyCron. Problem was not assigning permissions to the cron job -i.e. the triggered function did not operate properly with "guest" role.
    1 point
  7. I'm also using Twig with a custom translations system for interface text / code i18n. While the built-in multilanguage support for page fields is well-done, I don't really like the system and interface for code internationalization and localization, and it doesn't work with Twig files (which is probably why you want to build your own). I have written about the approach I took in the second part of my Twig + ProcessWire tutorial (towards the end, the section about translations). It comes down to a ProFields Table field that holds all the translations (so they can be edited through the backend as well) and a function that gets a local translation for the current language based on translatable strings (msgid). By the way I've switched to a Twig filter since writing this tutorial, I find it easier to write, so now I can simply do the following in Twig: {{ 'hamburger_button_label'|t }} If you do end up writing a module for this, make sure to publish it here as well, I've been looking for a more scalable approach ?
    1 point
  8. Will do. With no other confirmed replications yet, I'm wondering if it's a server config issue, although I've no idea what that may be. Thanks Edit: just seen Soma has replicated.
    1 point
  9. It's replicated on two servers, one running PHP 5 and the other PHP 7. It's also replicated in Chrome on a Windows machine, so it doesn't seem to be a Linux browser issue. The only other thing to try is a different internet connection. Thanks
    1 point
  10. This is now possible using owner selectors! http://processwire.com/blog/posts/processwire-3.0.95-core-updates/ $pages->find('template=repeater_collections_detail_images, your_repeater_field.owner.collections_detail_designer=123, include=hidden, sort=name');
    1 point
×
×
  • Create New...