Jump to content

Soma

Moderators
  • Posts

    6,798
  • Joined

  • Last visited

  • Days Won

    158

Everything posted by Soma

  1. http://processwire.com/talk/topic/941-accessing-values-from-%E2%80%9Cparent%E2%80%9D-template-when-page-is-rendered-within-another-template/ http://processwire.com/talk/topic/1510-templatedisplay-mode/ There's more but can't find. So you can also do: $somepage->contextpage = $page; echo $somepage->render(); And in the $somepage template if($page->contextpage->id == 1001){ ..
  2. jQuery and UI is required for the admin to work. Some inputs like images and ASM select etc. are depending on jquery and do not work without.
  3. Maybe this is even better http://modules.processwire.com/modules/template-decorator/
  4. http://processwire.com/api/cheatsheet/?filter=login&advanced The InputfieldPassword::matches isn't in there since it was also not in API documentation and also belongs to the InputfieldPassword module which is not part of the cheatsheet. Not every method there is is on the cheatsheet, lots of more advanced stuff is left out. Soon we gonna add new stuff that's added recently in 2.3.
  5. You can do this: if($user->pass->matches("yourpassword")){ // correct } But normally you just login and if it fails you know it's wrong. if($session->login("nam","password")){ // logged in }
  6. You better all come to the irc #processwire chanel. ;-)
  7. Thanks for the report Manfred! Must have had nervous fingers when editing in there. Will remove the double in the next update. Because it's not easy possible to style the file field across browsers. I'm progressively hidding and adding new text and button using jQuery. Since there's no text translation for the file upload buttons (it's translated by the browser), I had to somehow make it possible to localize it.
  8. Only if the template is in templates/ folder it works with both. But got caught on it on subfolders.
  9. It would be with the complete path $page->template->filename = $config->paths->templates . 'summary.php'; $page->render();
  10. So you got scared by that long complex basic form script? Creating form using ProcessWire as a framework and it's form and inputfield capabilities. Yes this would be possible and it's the way I use to make forms in front and backend whenever possible. Then we are finally here http://processwire.com/talk/topic/2089-create-simple-forms-using-api/ where I explained how to do it along with some examples. Yet another form example Since uploading files is a little special I went ahead and tried using the InputfieldFile to upload images to the temp folder and finally create a page and add those images same way as in the other examples. Then after success delete the temp files. Now this example does all the previous "pure" php example does, just using PW forms API. - required fields - CSRF preventing - inline error Form example snippet: https://gist.github.com/somatonic/5236008 There's also a CSS file example to style the form, and for example hide the "Drag files here...". This technique is the most simple to make front-end forms, and doing it this way allows you do add hooks to the form in case you need a custom validation or anything directly from within the template code. For example, the $form can be used to attach any hooks to the form: /* form hook example */ function hookEmail($event){ $file = $event->return; echo "email value: ". $file->value; } $form->get("email")->addHookAfter("processInput", null, 'hookEmail'); --- Little change to InputfieldFile.module to throw error if maxFiles is reached It works all well, but the maxFiles setting doesn't throw an error message when you choose more images than allowed. Since the InputfieldFile module is usually ajax based, it throws error via ajax and thus not in $form->getErrors() at all. It just proceeds and uploads only the max files and skips the rest. This could be changed in the module to also throw error on the field when no ajax is used. For this to maxFiles error to work I changed the /wire/modules/Inputfield/InputfieldFile.module a little: https://github.com/ryancramerdesign/ProcessWire/blob/master/wire/modules/Inputfield/InputfieldFile/InputfieldFile.module#L288 From: if($this->config->ajax) foreach($ul->getErrors() as $error) { $this->ajaxResponse(true, $error); } To: if($this->config->ajax) foreach($ul->getErrors() as $error) { $this->ajaxResponse(true, $error); } else { foreach($ul->getErrors() as $error) { $this->error($error); } } Maybe if Ryan can implement those to the Inputfieldfile to allow for front-end error to be shown, it would be great.
  11. Thanks Ryan for the heads up, there's some nice examples for advanced coders. Strange. Now, I also would have thought that with !$u->getErrors() it wouldn't work, but it still does! I went and did many tests after you posted this and I can't see any difference and it all works as it should. The code works with both and I haven't looked into it further (core). I wish to be proven wrong but it really does (at least for me here) :/ I think you got a valid point with checking for if there's files really uploaded at all... However this wouldn't work if image upload would be not required in your form. Also the example you posted is also not showing how you could make required fields and inline error/repopulating fields, prevent CSRF and double posts. It's still a great example but as said, not a "complete" example that can be used in a public front-end form. May or may not suiteable for people not knowing what they're doing and only copy paste. What I also think could be the problem on Matthews side is that the PHP upload and post max size isn't enough to upload the file. I also tested this and it seems to fails silently with no errors and just shows the form again. Maybe there's a way to get around it, but thought it might be an issue since there's no error thrown as it's apache upload interrupting? --- It can get somehow complex to add all checks and validation to a form server side, and the following post example is also just for showing what all there's involved to make a pure php form (using some PW internals). Yet another example I've spent couple hours creating a form upload example - with files (images) upload to a page file field - adds new page on the fly and adds uploaded images - prevents CRSF attacks, this also prevents double post by refresh page after submit - has required fields with error messages inline - repopulates form field in case an error happened or a required field was not filled in - sanitizing and saving values to a page - jquery example with disabled submit button on form submit The gist repo can be seen here https://gist.github.com/somatonic/5233338 You can configure some variables and array's at the top and add remove fields as you wish to the html form markup. Like this: // --- Some default variables --- $success_message = "<p class='message'>Thanks for your message!</p>"; // --- All form fields as nested array --- // using html form field name => template field nam, from the page you're going to create $form_fields = array( 'fullname' => array('type' => 'text', 'value' => '', 'required' => true), 'email' => array('type' => 'email', 'value' => '', 'required' => true), 'message' => array('type' => 'textarea', 'value' => '', 'required' => true), 'newsletter_subscribe' => array('type' => 'checkbox', 'value' => 0, 'required' => false), 'images' => array('type' => 'file', 'required' => true) ); // --- WireUpload settings --- $upload_path = $config->paths->assets . "files/.tmp_uploads/"; // tmp upload folder $file_extensions = array('jpg', 'jpeg', 'gif', 'png'); $max_files = 3; $max_upload_size = 1*1024*1024; // make sure PHP's upload and post max size is also set to a reasonable size $overwrite = false; // --- Page creation settings --- $template = "upload-entry"; // the template used to create the page $parent = $pages->get("/uploads/"); $file_field = "images"; $page_fields = array('fullname','email','message','newsletter_subscribe'); // $page_fields = define the fields (except file) you want to save value to a page // this is for the form process to populate page fields. // Your page template must have the same field names existent // ------------------------------ FORM Processing --------------------------------------- include("./form-process.php"); To set this up. 1. Create a template upload-entry used to save the form submissions. With all the fields you'll have in the form, and name them the same as in the $form_fields 2. Create a form-upload.php template used to hold the form config and markup code: (create a template in PW with this name and the page the form should be rendered) https://gist.github.com/somatonic/5233338#file-form-upload-php 3. Create a form-process.php file in the templates folder with the processing code (This is included in the template file above after the configuration part) https://gist.github.com/somatonic/5233338#file-form-process-php There's a basic styling CSS: https://gist.github.com/somatonic/5233338#file-form-css And the jQuery snippet used to prevent double posting when double clicking the submit. https://gist.github.com/somatonic/5233338#file-form-js This is some screen showing the form:
  12. Why so complicated? It's in jQuery $('body').on("dblclick", function(){ alert("double clicked"); }); Ah, just read again: click and double click on same. It does work with both.
  13. Look at the error. Something with your selector is wrong. The limit has some whitespace that is not allowed. Should be limit=10.
  14. NIce solutions. I would solve it differently and not work against the natural structure but anyway. 1st world problem However up to you, if you feel happy with it, ok. Wanted to point out that you should write: 'outer_tpl' => '||', Or it will throw a notice in debug mode and I think it may result in not closing or opening tag (maybe not)? It's expecting a || to split for the template to use. Well better just add it.
  15. I have to say when I first installed it also took a time to realize to change text and save before seeing an icon. But if I remember correctly I had to save and change 2 times to get it show up, is that intended? I think it would be better to show the icon from beginning to avoid confusion, and show a little text edit: too slow...
  16. Right with this structure it would look like this: <details class="pw-toc" open="open"> <summary>In this article</summary> <?php $treeMenu = $modules->get("MarkupSimpleNavigation"); $options = array( 'max_levels' => 1, 'current_class' => 'current', 'outer_tpl' => '<ol>||</ol>', 'show_root' => true ); $root = $page->parents->count == 1 ? $page : $page->parent; echo $treeMenu->render($options, $page, $root); ?> </details> The root here is found by counting what level, and either take parent or page itself as the root. -- You could also define root alternatively like maybe depending on the structure and templates: $root = $page->parent->template == 'article' ? $page->parent : $page; echo $treeMenu->render($options, $page, $root); So saying if parent page template is 'article' take current page->parent as root, if not we take current page assuming it's the top 'article' page and not a child.
  17. Yes it works. Page is added and image is saved to page. Working example is here: https://gist.github.com/somatonic/5207537
  18. Not exactly sure about the structure but you could try this: If you have /article/ /article/page1 /article/page2 /article/page3 Code on article page $root = $page; echo $nav->render(null, $page, $root); // $nav being instance of the module And on the child pages $root = $page->parent; echo $nav->render(null, $page, $root); $page being the current page and $root is from where it starts generating navigation. Yu could also use the various options available to make adjustments, if not needed you can set it to "null" as in the example.
  19. Ok I copied your code over and starting taking closer look and test. There was so many faults and things to change, I can't name them all. First off, I changed the input submit and changed to if($input->post->submit){..., since contactname in the form isn't required and just personal preference and a good practice. I made sure debug mode in true in /site/config.php. First submit, BANG!!! error: Fatal error: Exception: Can't save page 0: /about/: It has an empty 'name' field (in /Applications/XAMPP/xamppfiles/htdocs/pwprofile/wire/core/Pages.php line 514) #0 [internal function]: Pages->___save(Object(Page)) #1….. So it can't create and save the page because you don't assign a title nor a "name" to the page before saving. I moved the code around to add those. -- Then there was a wierd line: $contact_photo = $input->post->contact_photo; and later: $np->contact_photo = $contact_photo; // being the file POST Maybe a left off when trying something? -- Then after that, the assignment of the upload to the page image: foreach($files as $filename){ $uploadpage->contact_photo = $upload_path . $filename; } $uploadpage? should be $np -- At the end of when errors found you still have the contest_photo instead of contact_photo. // get the errors foreach($contest_photo->getErrors() as $error) $message .= "<p class='error'>$error</p>"; -- All in all nothing special and nothing wrong with the PW code in there, except the page name left out. But with debug mode on an easy spot. I created a gist with a working version of your code here: https://gist.github.com/somatonic/5207537 (I changed template and parent to my default install but nothing to worry about. I also commented out a bunch not needed to make it work.) Still with the validation of the form fields open to do, currently you only validate the upload and show errors.
  20. Dont want to be mean but have to say that I already built multiple working front end form examples that work. The one Reno linked would be what you do. So this is not so much about making a working example but to help you debug your code you messed up. :-P #hides behind stone# Of course yours has some more fields, but there's no validation happen on those, which I think should be the lesson here. To make it easy on this subject I would suggest looking at my other front end forms using PW forms and field that will make it more streamlined and easy. Its also in my gists examples.
  21. Much better... and just now I spoted (starting from top) an error if ($input->get->contactname){ Your form is method post and not get! So you would have easily spoted this already if you add an pseudo echo "Hello" after the if() to see it gets to after the check. As I said it's really simple if you go step by step and output vars to test and see if it really get's there.
  22. Im saying gist.github.com not github itself
  23. I didn't say move this discussion to github, but the snippet maybe?
  24. I also know what you're saying, but I have to strongly disagree. I could've write this in any other similar thread. The problem is the code posted in a wysiwyg is "horrible" to read and even copy it. Then after this is working (as with 1000 other code here in the forum), there comes the next who takes this code but need another feature.. then the game start again with same story same code but different bugs issues. What I would like to do is helping how to code and debug, not have 1 million snippets that are sometimes very bad coded and not complete best practice or not even working spooking around the forum. It already happened many times and it will get worse by time. I know what you're wanting to do and I understand, but in the long run what we are practicing here since 2 years is very bad for newcomers. We better this energy and time to help with little tutorials and snippets that are good to start with in a dedicated site/place.
×
×
  • Create New...