Jump to content

SamC

Members
  • Posts

    733
  • Joined

  • Last visited

  • Days Won

    9

Everything posted by SamC

  1. I'd be interested in reading this Good luck with the project, sounds exciting!
  2. Since starting my journey to actually learn programming, css is off the menu (but struggling to ignore the PW forum!). So with that in mind, a framework will be very handy indeed. I haven't got time to learn grid right now, nor would I use it anyway, too early days for me.
  3. Ah I see. I was thinking of: 1) Submitting the form 2) Post to form-process.php 3) Sanitize values, see which ones validate (with valitron) 4) Stick the valid ones in session as an array of form data along with which ones have an error, like: [ 'name' => 'Sam', 'email' => 'fail', 'message' => 'hi this is a message', 'phone_number' => 'fail' ] 5) Redirect back to original form 6) Repopulate the valid fields from session, error class on the rest If all fields are valid, after (3), just email form, redirect back to contact page (with now blank contact form) with success message. Is this a goofy approach? I don't see any other way if POST data has been cleared, either by session->redirect() (post to same page) or by a PRG pattern.
  4. Thanks everyone for the input here, it's very useful Regarding this, how does this stop duplicate submissions? I mean, the code doesn't run when the form hasn't been submitted ($input->post_submit), but when the form has been submitted, what happens on refresh? The last action was POST so doesn't the form attempt to POST again? This is one reason why I started using the PRG pattern, although tbh, I'd rather post to the same page, makes things simpler, especially if you're keeping form fields populated i.e. the ones that did validate. Regarding the nette docs, I didn't really understand them! I'm a mere beginner @bernhard
  5. Hi everyone, just writing a new tutorial as a 'break' from learning PHP. It involves making a contact form. In brief, the part of the form with the radios and a checkbox: contact.php <fieldset class="form-group"> <div class="row"> <legend class="col-form-label col-sm-2 pt-0">Choose a colour</legend> <div class="col-sm-10"> <div class="form-check"> <input class="form-check-input" type="radio" name="gridRadios" id="gridRadios1" value="red" checked> <label class="form-check-label" for="gridRadios1">Red</label> </div> <div class="form-check"> <input class="form-check-input" type="radio" name="gridRadios" id="gridRadios2" value="blue"> <label class="form-check-label" for="gridRadios2">Blue</label> </div> <div class="form-check"> <input class="form-check-input" type="radio" name="gridRadios" id="gridRadios3" value="green"> <label class="form-check-label" for="gridRadios3">Green</label> </div> </div> </div> </fieldset> <div class="form-group row"> <div class="col-sm-2"><a href="#">Terms & Conditions</a> (required)</div> <div class="col-sm-10"> <div class="form-check"> <input class="form-check-input" type="checkbox" name="checkboxAgree" id="checkboxAgree"> <label class="form-check-label" for="checkboxAgree">Tick to agree</label> </div> </div> </div> ...and the template where the form posts to (very early days work in progress): contact-process.php <?php namespace ProcessWire; // Sanitize user inputs $name = $sanitizer->text($input->post->name); $email = $sanitizer->email($input->post->email); $message = $sanitizer->textarea($input->post->message); // Radio button values $allowed_values = ['red', 'green', 'blue']; /** * Only allow allowed values above, returns NULL if anything other * than the values in the above array */ $radio_value = $sanitizer->option($input->post->gridRadios, $allowed_values); // DOES THIS NEED TO BE SANITIZED?? $checkbox_agree = $input->post->checkboxAgree; $submitted = $input->post->submitted; // Concantenate all the values $str = 'Name: ' . $name; $str .= '<br>'; $str .= 'Email: ' . $email; $str .= '<br>'; $str .= 'Message: ' . $message; $str .= '<br>'; $str .= 'Radio value: ' . $radio_value; $str .= '<br>'; $str .= 'Checkbox agree: ' . $checkbox_agree; $str .= '<br>'; $str .= 'Form is submitted: ' . $submitted; echo $str; Form outputs: Name: Sam Email: sam@test.com Message: Hi, this is a test message... Radio value: blue Checkbox agree: on Form is submitted: 1 So would it be necessary to sanitize the radio buttons so only red, blue or green are submitted, and also, what about the checkbox? Could a user manipulate the POST array to send values other than the ones I want? Maybe just being paranoid but don't want to give out information that I haven't checked first. Thanks
  6. Hi @Artomultiplo Sorry but this site never materialised. Maybe @Robin S would be able to help you more with this.
  7. Nice site, I like it! I think you have a couple of typos on the contact page though: 'Insginnia / Happiness Inside' and: 'Reach Insginnia' Might want to check the other pages just in case
  8. SamC

    Need a new mouse

    I think Ryan may have bought one by now To join in the fun though, my favourite mouse after trying many is the Roccat Savu. Fits like a glove, no RSI for my PC worn hands https://www.roccat.org/en-GB/Products/Gaming-Mice/Savu/
  9. This might help: https://www.pwtuts.com/processwire-tutorials/in-depth-look-at-the-images-field-type/uploading-and-rendering-images/ Not sure why there's two loops in there, I didn't fully understand your first post. Maybe like: <ul> <?php $child_pages = $page->children; foreach($child_pages as $child_page): ?> <li> <?= $child_page->title; ?> <!-- IF IMAGE FIELD SET TO ALLOW ONLY 1 --> <img src="<?= $child_page->image->url; ?>" /> <!-- OR IF IMAGE FIELD SET TO ALLOW MULTIPLE, GET THE FIRST ONE, not sure if 'first' or 'first()' --> <img src="<?= $child_page->image->first()->url; ?>" /> </li> <?php endforeach; ?> </ul> Presuming the image field itself is named 'image'. p.s. welcome to the forum @disall2000
  10. Sorry but I didn't actually make anything, the whole thing was hypothetical. TBH I still don't know how to approach different 'types' of users. Saving everything on a user template doesn't make sense to me when users will need different fields. I like the sound of @LostKobrakais approach best, using a user template simply for authentication and having a 'profile' or 'employee' template linked to the user. If you do work it out, feel free to share how you did it!
  11. I guess I haven't been doing anything complex enough to need a GUI. Just stuff like this: https://confluence.atlassian.com/bitbucketserver/importing-code-from-an-existing-project-776640909.html Forced myself away from dropbox and now have to use git on my two computers in order to sync my work. Otherwise I would have just kept putting it back. It's been interesting to say the least. Cool progress though!
  12. So do none of you guys use the command line for git? Using desktop apps instead?
  13. I saw a wordpress plugin in action the other day that was like this, some kind of block builder. Maybe a repeater matrix within a repeater matrix would work. [+ Full width section] [+ Column] [+ Body] [+Gallery] [+Image] Means an awful lot of pre-planning. ==EDIT== @Macrura beat me to it with the wordpress plugin.
  14. Thanks @FrancisChung I'll read that later this weekend (after the rugby of course!). I'm working on OOP php at the moment. Been creating classes and objects (using public/abstract/interface), extending them, implementing them, redefining functions, using constructors, working out the differences between public/private/protected/final properties/methods. Having a blast! I'll be off the bench and in the game one day! This does mean my MySQL chapter has been put on the back burner for now though... was getting bored with it tbh, just working in mysql workbench, create, alter, insert, delete, repeat, repeat again. It's important though so I'll go back to that soon enough.
  15. That statamic UI is seriously GORGEOUS! (is very much like craft cms). The PW repeater matrix field, as cool as it is, looks somewhat dated in comparison IMHO. Totally this. Some parts of my blog posts have a ckeditor field just for three or four words (yeah, I could add another type in there 'Short text' or something but I stupidly didn't): I actually set them to all open now by default because it's awkward and not fun editing specific parts when it's laid out like the above. And this is only half of the items!
  16. Great links, really cleared things up, thanks @bernhard.
  17. Just another general coding question. I've been mucking about with arrays today (made much more enjoyable with movie references...) along with various other things I tried to bake in for added learning. I wanted to ask about what the 'norm' is in PHP regarding modifying an original thing (by reference) or returning something new and working with that (by value). The code is this (just looking at the function and usage immediately after it): Version 1 <?php $json = '{ "Bill": { "first_name": "Bill", "last_name": "Preston", "age": 18, "location": "San Dimas" }, "Ted": { "first_name": "Ted", "last_name": "Logan", "age": 19, "location": "San Dimas" }, "Rufus": { "first_name": "Rufus", "last_name": null, "age": 52, "location": "Futuristic City" } }'; // return array $people = json_decode($json, true); // by reference function changeKey($currentKey, $newKey, &$arr) { if (array_key_exists($currentKey, $arr)) { $arr[$newKey] = $arr[$currentKey]; unset($arr[$currentKey]); } else { // error rather than returning original array throw new Exception("Key does not exist"); } } changeKey("Ted", "Ted Theodore", $people); foreach($people as $person => $arr) { echo "<h1>" . $person . "</h1>"; echo "<ul>"; foreach($arr as $key => $value) { $key = ucfirst(str_replace("_", " ", $key)); if (isset($value)) { echo "<li>" . $key . ": " . $value . "</li>"; } } echo "</ul>"; } Version 2 <?php $json = '{ "Bill": { "first_name": "Bill", "last_name": "Preston", "age": 18, "location": "San Dimas" }, "Ted": { "first_name": "Ted", "last_name": "Logan", "age": 19, "location": "San Dimas" }, "Rufus": { "first_name": "Rufus", "last_name": null, "age": 52, "location": "Futuristic City" } }'; // return array $people = json_decode($json, true); // by value function changeKey($currentKey, $newKey, $arr) { if (array_key_exists($currentKey, $arr)) { $arr[$newKey] = $arr[$currentKey]; unset($arr[$currentKey]); return $arr; } else { // error rather than returning original array throw new Exception("Key does not exist"); } } // assign modified array $people = changeKey("Ted", "Ted Theodore", $people); foreach($people as $person => $arr) { echo "<h1>" . $person . "</h1>"; echo "<ul>"; foreach($arr as $key => $value) { $key = ucfirst(str_replace("_", " ", $key)); if (isset($value)) { echo "<li>" . $key . ": " . $value . "</li>"; } } echo "</ul>"; } Both cases output: Bill - First name: Bill - Last name: Preston - Age: 18 - Location: San Dimas Rufus - First name: Rufus - Age: 52 - Location: Futuristic City Ted Theodore - First name: Ted - Last name: Logan - Age: 19 - Location: San Dimas So is there a preference? Thanks.
  18. @Monty this might help: https://www.pwtuts.com/processwire-tutorials/creating-a-main-menu-and-sub-menu-for-your-website/
  19. @DaveP I went over a similar topic to this a while back ...and it was suggested to leave the user as just email/password i.e. just the very basic authentication requirements and create a 'profile' page instead which is associated with a user (which is auto created when they sign up with a page ref field on profile back to the user page). For example, for users with different roles (admin vs member), they might not all need the same fields. Never been sure what approach to take as I've still not built anything with members yet. The setup of this could possibly be important for the OP though for maximum flexibility for the future. p.s. hi @NoWords welcome to the forum
  20. I've been thinking of hacking it too but as a last resort. The trouble with such workarounds is obvious, when they change the names of the classes, we need to make changes too and I already use some of these admin overwrites. Thanks for the tip though, at least I know where to look at How are you overriding styles in the admin? Never done this before.
  21. How are the headings different sizes in the first place? Been searching through the ckeditor code and can't find anything that seems to control it. You can change the rendered label (Heading 1, Heading 2...), use custom classes for each item, change the html tag that gets output but damned if I can find the part that controls the font in the select list itself. The format dropdown is a plugin which you can download and add to ckeditor. I can't find this plugin in my PW install so not sure how the format dropdown even exists on my body field.
  22. Was looking at this: https://docs.ckeditor.com/ckeditor4/latest/guide/dev_format.html#custom-block-level-text-formats-definition Might be useful but possibly only affects the output rather than the actual dropdown.
  23. Yep, that answers it thanks for some reason, I thought running code in tracy was like what "would" happen rather than being the equivalent of running the code in a template file. I think they refer to it as a brain fart... Same reason for me.
×
×
  • Create New...