SamC

Members
  • Content count

    265
  • Joined

  • Last visited

Community Reputation

152 Excellent

About SamC

  • Rank
    Sr. Member

Profile Information

  • Gender
  • Location
    Surrey, UK

Recent Profile Visitors

659 profile views
  1. Love a bit of Armin.
  2. My original code: $m->to($contactFormRecipient) ->from($email) ->subject('Contact form submission') ->bodyHTML($message) ->send(); // SEND #1 if ($m->send()) { // SEND #2 I totally didn't notice the parenthesis in the if block. Doh! It sends the mail, then returns true/false presumably. You were right in your first reply. Thanks @Harmen All working now Full code here (bootstrap 4 alpha 6): <?php namespace ProcessWire; wireIncludeFile("./vendor/vlucas/valitron/src/Valitron/Validator.php"); $captcha = $modules->get("MarkupGoogleRecaptcha"); $contactPageID = '1020'; $contactFormRecipient = 'MY_EMAIL_ADDRESS'; $name = $sanitizer->text($input->post->name); $email = $sanitizer->email($input->post->email); $message = $sanitizer->text($input->post->message); $v = new \Valitron\Validator(array( 'name' => $name, 'email' => $email, 'message' => $message ) ); $v->rule('required', ['name', 'email', 'message']); $v->rule('email', 'email'); if ($input->post->sendMe) { if ($v->validate()) { if ($captcha->verifyResponse() === true) { $message = " <html> <body> <p><b>From:</b></p> <p>{$name}</p> <p><b>Email:</b></p> <p>{$email}</p> <p><b>Message:</b></p> <p>{$message}</p> </body> </html> "; $mail = wireMail(); $mail->to($contactFormRecipient) ->header('Reply-To', $email) ->subject('JS Electrician form submission') ->bodyHTML($message); if ($mail->send()) { $session->flashMessage = "<h2>Thank you for your message! I will get back to you shortly.</h2>"; $session->sent = true; $session->redirect($pages->get($contactPageID)->url); } else { $session->flashMessage = "<h2>Sorry, an error occured. Please try again.</h2>"; } } else { $session->flashMessage = '<h2>Recaptcha must be complete.</h2>'; } } else { $session->flashMessage = 'Please fill out the fields correctly.'; } } ?> <div class="container"> <div class="row justify-content-between"> <div class="col-sm-12 col-lg-8 py-3"> <?php if($session->flashMessage):?> <div class="alert <?php echo $session->sent ? 'alert-success' : 'alert-danger'?>" role="alert"> <?php echo $session->flashMessage;?> </div> <?php endif;?> <form id="contact-form" method="post"> <div class="row"> <div class="form-group col-sm-12 col-lg-6 py-2 <?php echo $v->errors('name') ? 'has-danger' : ''?>"> <label for="name">Name (required)</label> <input class="form-control" name="name" id="name" type="text" value="<?php echo $sanitizer->text($input->post->name); ?>"> </div> <div class="form-group col-sm-12 col-lg-6 py-2 <?php echo $v->errors('email') ? 'has-danger' : ''?>"> <label for="email">Email (required)</label> <input class="form-control" name="email" id="email" type="text" value="<?php echo $sanitizer->text($input->post->email); ?>"> </div> </div> <div class="form-group py-2 <?php echo $v->errors('message') ? 'has-danger' : ''?>"> <label for="message">Message (required)</label> <textarea class="form-control" name="message" id="message" rows="8"><?php echo $sanitizer->text($input->post->message); ?></textarea> </div> <div> <!-- Google Recaptcha code START --> <?php echo $captcha->render(); ?> <!-- Google Recaptcha code END --> </div> <div class="form-group"> <button type="submit" class="btn btn-primary" name="sendMe" value="1">Send message</button> </div> </form> </div> <div class="col-sm-12 col-lg-3 py-3"> <h2>Have a question?</h2> <p class="mb-0"><i class="fa fa-phone" aria-hidden="true"></i> <?php if($clientPhone) echo $clientPhone; ?></p> </div> </div> </div> <?php $session->remove('flashMessage'); $session->sent = false; echo $captcha->getScript(); ?>
  3. Thanks @Harmen but the next block relies on the return value of send() to show the flash message like so: if ($m->send()) { $session->flashMessage = "<h2>Thank you for your message! I will get back to you shortly.</h2>"; $session->sent = true; $session->redirect($pages->get($contactPageID)->url); } else { $session->flashMessage = "<h2>Sorry, an error occured. Please try again.</h2>"; } Would you mind sharing the code for your form so I can have a look at how you approach this?
  4. I can't work out what the problem here is. I have a simple contact form: <?php namespace ProcessWire; wireIncludeFile("./vendor/vlucas/valitron/src/Valitron/Validator.php"); $captcha = $modules->get("MarkupGoogleRecaptcha"); $contactPageID = '1020'; $contactFormRecipient = 'MY_EMAIL_ADDRESS'; $name = $sanitizer->text($input->post->name); $email = $sanitizer->email($input->post->email); $message = $sanitizer->text($input->post->message); $v = new \Valitron\Validator(array( 'name' => $name, 'email' => $email, 'message' => $message ) ); $v->rule('required', ['name', 'email', 'message']); $v->rule('email', 'email'); if ($input->post->sendMe) { if ($v->validate()) { if ($captcha->verifyResponse() === true) { $message = " <html> <body> <p><b>From:</b></p> <p>{$name}</p> <p><b>Email:</b></p> <p>{$email}</p> <p><b>Message:</b></p> <p>{$message}</p> </body> </html> "; $m = $mail->new(); $m->to($contactFormRecipient) ->from($email) ->subject('Contact form submission') ->bodyHTML($message) ->send(); if ($m->send()) { $session->flashMessage = "<h2>Thank you for your message! I will get back to you shortly.</h2>"; $session->sent = true; $session->redirect($pages->get($contactPageID)->url); } else { $session->flashMessage = "<h2>Sorry, an error occured. Please try again.</h2>"; } } else { $session->flashMessage = '<h2>Recaptcha must be complete.</h2>'; } } else { $session->flashMessage = 'Please fill out the fields correctly.'; } } ?> <div class="container"> <div class="row justify-content-between"> <div class="col-sm-12 col-lg-8 py-3"> <?php if($session->flashMessage):?> <div class="alert <?php echo $session->sent ? 'alert-success' : 'alert-danger'?>" role="alert"> <?php echo $session->flashMessage;?> </div> <?php endif;?> <form id="contact-form" method="post"> <div class="row"> <div class="form-group col-sm-12 col-lg-6 py-2 <?php echo $v->errors('name') ? 'has-danger' : ''?>"> <label for="name">Name (required)</label> <input class="form-control" name="name" id="name" type="text" value="<?php echo $sanitizer->text($input->post->name); ?>"> </div> <div class="form-group col-sm-12 col-lg-6 py-2 <?php echo $v->errors('email') ? 'has-danger' : ''?>"> <label for="email">Email (required)</label> <input class="form-control" name="email" id="email" type="text" value="<?php echo $sanitizer->text($input->post->email); ?>"> </div> </div> <div class="form-group py-2 <?php echo $v->errors('message') ? 'has-danger' : ''?>"> <label for="message">Message (required)</label> <textarea class="form-control" name="message" id="message" rows="8"><?php echo $sanitizer->text($input->post->message); ?></textarea> </div> <div> <!-- Google Recaptcha code START --> <?php echo $captcha->render(); ?> <!-- Google Recaptcha code END --> </div> <div class="form-group"> <button type="submit" class="btn btn-primary" name="sendMe" value="1">Send message</button> </div> </form> </div> <div class="col-sm-12 col-lg-3 py-3"> <h2>Have a question?</h2> <p class="mb-0"><i class="fa fa-phone" aria-hidden="true"></i> <?php if($clientPhone) echo $clientPhone; ?></p> </div> </div> </div> <?php $session->remove('flashMessage'); $session->sent = false; echo $captcha->getScript(); ?> So validation works fine, the flash messages work, the only thing that's wrong is in my gmail app (or gmail in the browser - this form is sending to a gmail address). I receive it twice, but the second one is like it's being forwarded back to me? Is weird, here's what it looks like once I've submitted it: ...then if I expand the [...] quoted text bit... Can anyone see or suggest why this might be happening? Thanks for any advice
  5. Have some fun with it. There's no magic, it's all in the docs. Go to the docs, read, test, read some more, test again. This was a total boost for me at the beginning. The docs are excellent and explain a lot of things. For example, you could start here: https://processwire.com/api/variables/pages/ What I'm saying is, the help pages link so well together that every time new questions are kicked up, the answer is just a few clicks away. And this forum is phenomenal for support. Stick with it, you'll be able to make some cool things in no time. Once you find a way that suits you in terms of organising your data in your site, the templates, fields etc... then it's just a matter of getting stuck into the docs to find a way to print these values to a webpage. Further in, you'll probably want to do some more complex things with the data, but deal with that when you get there.
  6. I'm not sure either, but did you try it?
  7. Out of curiosity, would this work? $articles = $pages->find("template=project, sort=-date "); foreach ($articles as $article) { // from https://processwire.com/api/modules/select-options-fieldtype/#outputting-selected-options-on-a-page $n = $article->number->title; // <<<< the value of the selected option $thumbs = $article->images->slice(0, $n); foreach($thumbs as $thumb) { echo "<img src='$thumb->url' >"; } }
  8. Some good suggestions, thanks. Just gonna crack on with a test site and see if I can put this together. Can I just clarify something, when we talk of creating new users, are we saying all users will be listed at '/access/users/'? Or do they sometimes get created in the page tree? (I'm talking generally, not edge case) Also, (in @LostKobrakai's approach) if having minimal fields in the user template means having a second template, wouldn't deleting a user in the admin (when logged in as superuser) mean also having to delete the associated profile page manually? Everything seems to be doubled up. I'm sure my preferred method will become clear once I've played around with it.
  9. I can only see a missing '}' at the end to close the first loop (presuming an incomplete copy/paste), the rest looks ok to me. I just tried slice in something similar and works fine. // home.php with images field called 'images' <?php $toRender = $page->images->slice(0, 2); // 2 of 4 available images foreach($toRender as $image) { echo "<img src='{$image->url}' />"; } ?> Be interested to see what's wrong here.
  10. @Robin S ah I see, I've never used that. Thanks for the info.
  11. Thanks @LostKobrakai This sounds like a sensible way to organize, Ilike it. So I'd do this? User (template) - name - email - password Profile (template) - avatar - social media link - page ref (to user) ...how would I link the two? A page ref field on profile to user? I'd like to manually create a few users to test this. But if you had 100,000 users, that'd be hell of a long dropdown list on the page ref field. I'm guessing it would be better to do this programmatically in a template when a user signs up to create a matching profile when the user is created. Is this what's meant here?
  12. Thanks @arjen that's a decent explanation but I'm still not 100% clear on this. I think it would be helpful if we could define what is meant by a user (or use different terminology to show what type of user they are). This confuses me a bit when people talk about 'users'. To me, there are different types of users (of the logged in to your site variety). For example, an admin could have superuser role, staff could have a 60% permissions client role (maybe excluding config/permissions sections or something), and members (i.e. people who are a member of your site, who can only change their email/password/avatar) with a member role. So in the above case, how would you handle something like this: 1) An admin may only need name, email, password. 2) Staff may have fields, email, phone, address, department, name, email, password. 3) A member may have avatar, email, social media profiles, name, email, password. Is it just a case of putting EVERY possible required field onto the user template, then users (I mean anyone who logs in) would just fill in the fields they require? Or did I just describe an edge case? I've seen situations on the forum which describe having users as part of the page tree. Would this be a normal way to do things if you had 100,000 members? Or would they all be listed in '/access/users/'? I've set up a local site in which I am going to experiment with user profiles to see if I can get this sorted in my head.
  13. I wanted to create a client profile with fields: profilePicture clientEmail clientAddress clientPhoneNumber profileFacebook profileTwitter profileLinkedIn profileGooglePlus ...etc. At the moment, this lot sits in a template called 'site-settings' but they should really be associated with a user. Ok, so this site only has one user so it doesn't matter, but I'm looking at future practice and if the site had multiple users, assigning the above to each user would be impossible. I created a new role called 'client'. So I have a couple of questions. Hypothetically, my new site will have 10 client accounts, each with the same fields as above: 1) Would I assign these fields to a ROLE (rather than a user, where name, email, password and role fields seem sufficient), then create new user with this role? 2) How do I add fields to a role? I'm confused between 'modules/configure/processRole' and 'modules/core/processRole'. Both of these urls have a way to add fields, but what's the difference? Any advice would be awesome, thanks. --EDIT-- Are roles just for permissions? --EDIT-- Wait, I just saw there's 'processProfile' and 'processUser' (in core and config dropdowns). Even more confused now.
  14. @Robin S I just checked this out and confused now as to where the mystyles.js fits in with this. Could you elaborate please?
  15. Exact problem I just had with an undefined function, damn namespace! Keep forgetting it. Thanks @Zeka