Jump to content

Guy Incognito

  • Posts

  • Joined

  • Last visited

Everything posted by Guy Incognito

  1. Hi all. We've created a private log-in area for a client on their site that is restricted on a roles basis. Is there a simple solution available to let them upload files to a file field and then choose individual users that can access individual files? Does that make sense?!... it's hard to search for answers to this as all results pertain to server file permissions.
  2. Just wondering what software/approaches others take to the management of their code snippets. Relatively new to PW and finding that its logical approach is making it far easier for me to reuse code in projects and encourages me to try and be more organised! I've looked at few notes apps that piggyback of Gists - although I'm not sure if Gists is a good idea for private project work seeing as they're never totally private.
  3. Awesome thanks - this has been a useful lesson 🙂 I think my inital confusion on this stemmed from my hook function being my own code and not part of PW, but I guess as it is an extension of an existing class then it makes sense the other variables should be accessible. (I may be rambling here... but I know what I mean!).
  4. Ah ok - that's interesting thanks. So are all Processwire object accessible like this within hook context?
  5. GOT IT! ....obvious mistake in hindsight! I needed to pass the $page object into the closure. Because I'm populating the email to field from a page template field it wasn't getting populated as the $page object wasn't there. so $loginRegister->addHookAfter('createdUser', function($user) use (&$mail) { becomes $loginRegister->addHookAfter('createdUser', function($user) use (&$mail, &$page) { Thanks all 🙂
  6. The wireMail code definitely works as it was ported from another project. But double checking this has narrowed it down a bit thanks - It's definitely something to do with how I'm implementing the hook as if I move the mail sending code out of the hook it works fine.
  7. Hi all, I'm trying to hook the createdUser method of @ryan's LoginRegister module to send a notification by email to site admins when someone registers and clicks the confirm link. But struggling to get it to work. Any pointers much appreciated. I think I'm getting code blindness! 😛 I think the error may relate to my use of anonymous functions which I haven't used much in PHP before or object scope. I've also not made much use of ProcessWire hooks to-date either! (In at the deep end here). I know the hook fires as if I replace my wireMail code with a simple echo and die() it works. I'm not getting any errors, but no message gets sent. $loginRegister = $modules->get('LoginRegister'); $loginRegister->addHookAfter('createdUser', function($user) use (&$mail) { // Init wiremail $notificationMsg = $mail->new(); //Prep message body $msgTitle = 'A new user has registered'; $msgContent = 'Email message content'; $msgBody = '<p style="font-weight:bold;font-size:20px;">'.$msgTitle.'</p><p>'.$msgContent.'</p>'; //Create array of recipients (from on-page repeater field) $emailRecipients = array(); foreach ($page->notification_recipients as $receipient) { $emailRecipients[] = $receipient->email; } //Create array of recipients (from charge page repeater field) $emailRecipients = array(); foreach ($page->notification_recipients as $receipient) { $emailRecipients[] = $receipient->email; } //Send message $notificationMsg = $notificationMsg->send( $to = $emailRecipients, $from = 'no-reply@mydomain.com', $subject = $subjectMsg, $options = [ 'bodyHTML' => $msgBody ] ); }); $loginRegister->set('renderStyles', false); $loginRegister->execute();
  8. @Raj I second @Soma‘s advice. There’s a lot of great PW tutorials listed here: https://processwire.com/docs/tutorials/ You don’t sound like you’re a million miles away from what you’re looking to achieve and as per Soma’s comment I would just reload your script to check for submission rather than worrying about Ajax upload. Definitely recommend checking the tuts above out, it’s where I started with PW and I’ve not looked back! I’ve found PW to be the easiest CMS to get to grips with and it’s also really pushing my PHP skills to new places too :-) because the core is so well organised it allows you to be more creative with what you want to do.
  9. Still only on my iPad at mo so just guessing but don’t you need todo something like $files[0]->url to get the complete path?
  10. Does the user field get updated successfully? I’m not in front of my computer at the moment to check but from my memory the file doesn’t stay in the upload folder it gets moved to the folder where all your site image uploads go.
  11. Ah perfect - yes can confirm works as follows: echo $templates->get('dog')->fieldgroup->getField($field['name'], true)->label; New it would be available somehow - Thanks for your help 🙂.
  12. Thanks @dragan - but no luck with the methods in that thread either. Just to reiterate, I'm not having any problems displaying the labels. It's just that the labels being output by PW are the default field labels set in the global field editor, not the override labels applied to those fields in the template editing interface. See screen grab: Note: The field names display correctly for fields using their default names - it's just the overridden ones that don't work.
  13. I'm pulling all the fields from a template type, in this particular instance 'dog'. I'm getting all the template fields by: $t = $templates->get("dog"); $dogFields = $t->fields; The looping through my $dogFields object to output the fields as per snipper earlier. I have overridden the 'title' field in this template to be called 'dog name' as it just makes more sense in this context, but I can only ever seem to output the field's original default name 'title'. Obviously I don't want to rename the title field globally.
  14. I've overridden the name of the some fields on a template, but I can't seem to output the updated names on the front end. PW outputs their original names regardless of what is being displayed in the template editor. Is this correct behaviour? Currently looping through to get fields outputting each as follows: echo '<input type="text" name="'.$field['name'].'" class="form-control" id="'.$field['name'].'" placeholder="'.$field['label'].'">'; When I dump my $field object there doesn't seem to be any output for the overridden labels in the array, is there another way to do this?
  15. Ignore me... had the path wrong! Works if you use: cache/.avatar_uploads/
  16. I'm just experimenting with your idea @Soma as I hadn't thought about this approach for securing the upload folder before. Using the path as you described throws an error though, even if I manually create the .folder. Error: Exception: No upload path! Should PW automatically handle this path or does it need me to configure this folder somewhere? Or perhaps the server doesn't allow the .folders?
  17. Ah perfect thanks - all makes perfect sense now you've spelled it out to me - reloading the user object solves the issue 🙂 And yes - addressing the security issues above is in my todo list - this was just a prototype based on examples on this forum and it was bugging the hell out of me why the image wouldn't load first time!
  18. This was my original guess. Query string is a good idea but doesn't seem to make any difference. 😕 I've tried as follows: action="./?<?=substr(base64_encode(mt_rand()), 0, 15);?>"
  19. I'm trying to implement a front-end image upload form for user profile pictures, to a field called 'profile_picture'. The code is based on the various examples found around these forums but isn't yet 100% right. The form successfully submits the image to the server and updates the field in the dashboard. When you submit the firm, the page reloads and uploads the image but the template still loads the old image path (now broken path as the old image has been removed). I can only get the new image to show if I hit enter in the address bar forcing the page to reload. Any ideas? Is it a caching issue, or something to do with the order of the script? It makes no difference if I call the image after the upload form. <?php //Display current user image $userImg = $user->profile_picture->first(); echo '<img src="'.$userImg->url.'">'; $upload_path = $config->paths->assets . "files/avatar_uploads/"; $f = new WireUpload('userimage'); $f->setMaxFiles(1); $f->setMaxFileSize(1*1024*1024); $f->setOverwrite(true); $f->setDestinationPath($upload_path); $f->setValidExtensions(array('jpg', 'jpeg', 'png', 'gif')); if($input->post->form_submit) { if(!is_dir($upload_path)) { if(!wireMkdir($upload_path)) throw new WireException("No upload path!"); } $files = $f->execute(); if ($f->getErrors()) { foreach($files as $filename) @unlink($upload_path . $filename); foreach($f->getErrors() as $e) echo $e; } else { $user->of(false); $user->profile_picture->removeAll(); // wirearray (line added by @horst: explanation is three posts beneath) $user->profile_picture = $upload_path . $files[0]; $user->save(); $user->of(true); @unlink($upload_path . $files[0]); } } ?> <form class="forum-form" accept-charset="utf-8" action="./" method="post" enctype="multipart/form-data" > <input type="file" id="attach" name="userimage" accept="image/jpg,image/jpeg,image/gif,image/png" /> <input type="submit" name="form_submit" value="Submit"/> </form>
  20. I'm going to use their email for login, but planning to use their username for display around the site so thought it would be nicer for them to choose their own. If solving this becomes too much of a PITA I'll probably just settle for displaying first name and first letter of their last name instead. E.g. Joe Bloggs becomes JoeB.
  21. I already tried changing that setting - but it doesn't seem to make any difference to whether or not the name field shows?
  22. Hi, I'm just setting up @ryan's LoginRegister module for a project. Just wondering is there a way to make the PW user 'Name' field included in the registration/profile output? It's available to me in the drop-down and I've made the field user editable too.
  23. Ok cool thanks - had read that thread and was secretly hoping for 'hidden option c' that I hadn't yet come across that would allow me to keep the file in templates without relating it to a page!
  24. I'm trying to make an AJAX call from within a template to a php script within my templates folder, but I'm getting a 404 from all URLs. Is there a proper way to directly address scripts within PW templates? I've read it will work in the site root, but I'd rather keep all the code together if possible.
  • Create New...