Jump to content


  • Posts

  • Joined

  • Last visited

Everything posted by modifiedcontent

  1. I am trying to put together a front end form for a repeater field. The solution in the previous post gives helpful clues, but my repeater field doesn't need new pages and templates I think - isn't that a Page Reference field? My repeater field is for RSS feeds; name 'feeds', type 'Repeater'. The field used by 'feeds' is name 'rssfeed', type 'URL'. To store a regular field I'd use something like this: But instead of one value it would be adding one or more values to an array, somehow done with the fieldname[] and for ( $i=0;$i<$fields;++$i ) stuff, but without new Page() and template etc.? Not sure how to put that together, will try things this weekend... Is there a code example somewhere? Is there a way to get the same fancy repeater input field as in the admin area?
  2. Thank you @horst! That was the problem. I was using $sanitizer->text() on the field. If I remove that it works fine. There is a $sanitizer->textarea() and $sanitizer->purify() is probably best for my use case.
  3. Input from a textarea field via the front-end gets truncated; only the 246 characters (with spaces) get saved, nothing longer. When I enter text for the same body field via the admin back-end there is no limit and it also shows up fine on the front-end, but when I edit and save that same longer text from my front-end form, it gets cut at the same spot around 246 chars. I have tried with and without Ckeditor, but that makes no difference. I guess I can eliminate Ckeditor as a possible cause. What else could it be? This may be related or not. Any other ideas appreciated.
  4. Why would I do that? I now have the delete button figured out - with your help! - so why would I start over again? I do normally avoid modules and try to use built-in methods that I understand. Agreed with your point. But for the comments section, this is a module by our fearless leader @ryanand as far as I understand it, I like his approach; looks like a solid future-proof basis to move forward with. So I need to sort out an edit button next, probably next Christmas... If anyone has any ideas, please post in this thread. I guess for an 'edit' button you would use updateComment()? Edit field via ajax?
  5. Comment delete button The delete button itself; only shows up for the logged-in author of the comment: jQuery to handle a click on the delete button via ajax: PHP to process the ajax request and delete the comment: This seems to work. Let me know if you see mistakes or ways to do this better. Next I need a comment edit button...
  6. Hello @Jan Romero, thank you so much. This gives me a lot of new stuff to work with and try tomorrow morning. 🙂 Happy New Year! Edit: I kept getting similar errors with your suggestions, but after trying a lot of variations with your input, this seems to work: $field = $page->getField('comments'); $comment = $field->getFieldtype()->getCommentById($page, $field, '26'); if ($comment !== NULL) { $field->deleteComment($page, $comment); } Still not entirely sure what getFieldtype() does, but that is apparently essential. Thank you! Now putting together the complete comment delete button solution, will post in next comment below...
  7. Does anybody know how to use $fieldtypeComments->deleteComment($page, $field, $comment)? See previous post for details. Or how to use functions like this in general. A 'basic usage' is given, but I can't find examples and whatever I try I get errors like 'Call to undefined function' or 'Argument 2 ... must be an instance of Comment' or 'Call to a member function ... on null' or 'Class 'CommentArray' doesn't yet implement method 'makeBlankItem()' and it needs to' or it complains about wrong use of $this because not in context or whatever. Running out of ideas, so please help if you understand this stuff.
  8. How can I use deleteComment()? I posted a question here, but have been trying to figure it out here. Still stuck, so please help.
  9. How can I use $fieldtypeComments->deleteComment($page, $field, $comment) to delete a comment if I have the comment's ID? I have the ID of the comment, but I guess this function needs the entire object? So I guess I first have to use this: $comment = $fieldtypeComments->getCommentByID($page, $field, int $id); Are $page and $field required for both? $page is the page where the comment is on I guess, but where do I get $field? What does return value 'mixed' mean? I see the delete function returns a variable $result, so I'll try to echo that. How should I put this together? Are there examples anywhere? If I echo $page from within my comments.php file, I get an ID that should be usable for the delete function, but I get nothing from $field. What the hell is that $field supposed to be? Where can I get it? This put in a template with the comments produces `Uncaught Error: Call to a member function deleteComment() on null`: $fieldtypeComments->deleteComment( '3156', 'comments', '25' ); I get the same error on any $fieldtypeComments-> function. Should I use FieldtypeComments:: instead? Or $this->...? Or wire()something? Or "declare" a class or globals? Please point me to the basics if you know. This produces a more promising `Uncaught TypeError: Argument 3 passed to FieldtypeComments::deleteComment() must be an instance of Comment, string given`: FieldtypeComments::deleteComment( $page, $field, '25' ); Trying to get a $comment instance (?), this produces another error: `Fatal Error: Uncaught Error: Using $this when not in object context in ...`: $comment = FieldtypeComments::getCommentByID($page, $field, '25'); I see there is also a public function deleteComment() in commentfield.php that doesn't require $field, but requires (?) $notes: I still get `Fatal Error: Uncaught Error: Call to undefined function deleteComment() in...` when I try that in different places in the template. Getting closer. This produces some kind of result: CommentField::deleteComment($page, 25, $notes = ''); Still results in Fatal Error: Uncaught TypeError: Argument 2 passed to CommentField::deleteComment() must be an instance of Comment, int given ... I have also tried $comment, $comment = "25" and "25", but got the same error. What is 'an instance of Comment'? How can I get it? This produces an interesting error: $comment = $page->comments->get('25'); CommentField::deleteComment($page, $comment, $notes = ''); Error: Exception: Class 'CommentArray' doesn't yet implement method 'makeBlankItem()' and it needs to. (in wire/core/WireArray.php line 197) ??
  10. @tires , to use Full Name, or whatever field you need, I now use this in CommentListCustom: And then use {fullname} in your markup instead of {cite}. Continuing my Christmas tradition; upgrading my websites. Last year I got a basic comment system working. This Christmas I want to add edit/delete buttons to comments, absolutely essential for any modern comment system. How can I do that? I have a working comment system based on these CommentListCustom and CommentFormCustom files. 'delete | edit' buttons would go somewhere in CommentListCustom, something like this in the CommentFooter: <div class='CommentFooter'> <p class='CommentAction'> {reply} {permalink} | delete | edit </p> </div> The 'delete | edit' buttons - later icons of course - should only show up for the author of the comment, so they would be wrapped in something like this: if ( $user->isLoggedin() && $user->name == {cite} ) { echo 'delete | edit'; } Using '{cite}' there would probably not work, right? What should I use instead? To delete a comment I would have to identify the comment and then do something like $comment->delete(); somewhere I guess. These comments are not pages I think, so maybe deleting them works differently? Comments are numbered, like id="Comment24" and data-comment="24". How can I target that ID to delete that comment? Or could I just use clever/complicated PHP magic like $this to target the element the delete button is in? Or was that jQuery...? Are we using jQuery anyway to process these actions? I see $this->etc. is used a lot in CommentListCustom. I see there is a 'delete comment' method here. // basic usage $mixed = $fieldtypeComments->deleteComment(Page $page, Field $field, Comment $comment); And for an 'edit' button I would use updateComment()? What values would these functions use? $page would be the page the comment is on I guess. Wouldn't $field be comment field by definition? Would the value for $comment be that ID number? Is there a code example how to use these somewhere? The deleteComment() function in FieldtypeComments.module: Should I just "do" `$this->deleteComment($page, $field, $comment);` and if triggered from within the element it will delete that comment including replies if any? Use jQuery or PHP? Something like this? Or use jQuery as event handler and then somehow trigger a PHP function? I know how to post form data via ajax, but how would that work with `deleteComment($page, $field, $comment)`? The jQuery would send those variable values to a php file with the function that would send a result back to the element I guess. This works to alert the comment ID: Now I can send that comment ID to PHP via ajax and do `deleteComment($page, $field, $comment)`. What should I use for $page and $field? I guess the ID of the page the comment is on, but what is $field supposed to be?
  11. I want to replicate /admin/profile in a styled front-end member account settings page - keep members out of the admin back-end entirely. Is there a quick, built-in way to add those form fields to a template? In particular/for starters/for example Set Password. I already have a working version with a simple form processed like this: if($input->post->updatepass) { $pass = $input->post->pass; if($pass) { if(strlen($pass) < 6) { $winorfail = '<p class="textblock error">Your new password must have at least six characters.</p>'; } else if($pass !== $input->post->pass_confirm) { $winorfail = '<p class="textblock error">Your passwords do not match.</p>'; } else { $user->of(false); $user->pass = $pass; $user->save(); $user->of(true); $winorfail = '<p class=textblock>Your password has been changed.</p>'; } } } But I bet this is horribly unsafe and incomplete. The PW back-end version also asks for the current password for example. Is there a standard "tag" or function or line of code I can use to get the built-in PW processes for these fields? Or should I be able to find the block of code and copy/paste - what keywords should I search on? Or am I on the right track and should I just keep using forms + processing like above? I know how to replicate simple text and textarea field etc. and have even figured out a working image upload. But how can I replicate a Repeater field on the front-end, with all the nice UI magic I get on the back-end? How could I get image upload on the front-end with the same UI as in the back-end? Edit: I found a few other questions about Repeater fields in front-end forms here and here. This looks promising. I'll try that and post findings on that thread.
  12. I'm trying to use an RSS feed with an unusual format that works fine in browsers, but PW's field checker keeps rejecting it. I've tried several variations of this: ... /__rss/website-scheduled-content.xml?input={"sectionAlias":"process"} ... /__rss/website-scheduled-content.xml?input=%7B%22sectionAlias%22%3A%22process%22%7D Any ideas how to get this through? Edit: Nevermind, I see the HTML Entity Encoder on the field has an option to allow single/double quote characters. That fixed it.
  13. You can use the API to integrate content from Processwire into Wordpress. Haven't thought this through, can provide more details later, would be messy anyway...
  14. I want to quickly remove the picture upload button from Ckeditor - it doesn't play nice with Processwire or does it? I appreciate this thread, because I am always very confused how to customize the editor, although I have done it several times before. Where are these settings? I have to edit directly in a Ckeditor js file somewhere, right? Or does Processwire have a built-in settings editor somewhere? I see there is some explanation here... That makes customizing the editor for PW fields not that difficult; settings are in the Input tab for the field that uses Ckeditor. But I see I am using a second Ckeditor on the front-end, that I'll have to customize in the js file I guess. I should figure out how to use the editor that comes with PW instead...
  15. Thanks for the response @Jan Romero. I was looking in that direction. I think 'profile-edit' is for admin/profile/, which is based on the system 'user' template. I use another 'profile' template for pages created when members register with the site. Today I have tried to figure out if I could replace that 'profile' template by the 'user' template, but I can't make it work for some reason. I can just keep using 'profile' I guess and get all the content from 'user' anyway, but is there any way to edit the template of /admin/profile/? The use of the (user)name instead of First Lastname annoys me. And I'd like to replace the Processwire logo/icon with the site + homelink etc.
  16. I am working on a membership system. I have a parent page 'members' and until now used a child page 'profile', but am now trying to replace the 'profile' template with the 'user' system template - makes more sense, no? The 'user' template won't show up as a template option in page edit Settings. I have checked Family in the template setup; 'members' is the allowed parent for the 'user' template and 'members' has 'user' as allowed template for children. 'Don't allow pages to change template' in Advanced is also off for all involved templates. What am I missing? Can the system 'user' template even be used for pages or does it work differently?
  17. I want to give members of my site access to their profile page edit in admin, but I don't want them to go up the tree and start editing other members pages - which is what could happen if I control access by the template 'profile' only. How can I make sure members can only edit their own profile page? In the profile template, for the front end, I have something like `if ( $user->isLoggedin() && $user->name == $page->name )` to restrict edit access to the page owner. In the back end there are parameters on the URL, like admin/page/edit/?id=1388 How can I target that? I can get the currently logged-in user's profile page ID; if they are trying to edit another page ID, they should be blocked/redirected. Can I add something in admin.php to achieve that? I see Ryan Cramer has a PageEditPerUser module, but it is very old, very beta and requires to enter allowed pages manually. AdminRestrictBranch seems more stable and has a Custom PHP option - trying to figure that out now...
  18. Found a solution based on @Fokke's solution from 2015. Adding the following in admin.php, before the line `require($config->paths->adminTemplates . 'controller.php');` gets me the behavior I needed; Settings only shows up for the SuperUser: function hideSettingsTab(HookEvent $event) { // Get the page being edited $page = $event->object->getPage(); if ( !wire('user')->isSuperuser() ) { $page->template->set('noSettings', 1); } } $wire->addHookBefore('ProcessPageEdit::buildForm', null, 'hideSettingsTab'); This solution is easy to adapt for whatever your needs are.
  19. Is there a way to hide the Settings tab in admin/page/edit by role? I am fine-tuning my members view. Processwire is such a nice system, so much access control by fields and templates etc. But I can't figure out how to hide the Settings tab. I want members to be able to edit their profile page, but not change the "slug", template, publication status, etc. Using access/roles/edit I think I can block access to 'change template' with 'revoke from: template', but the template still shows up in Settings, not editable with or without revoke - I made that unchangeable somewhere else. The slug name is editable and really shouldn't be for members. I see there is a module for this - haven't tested yet... Is that still the way to go or is there a build-in solution?
  20. @Rudy, thanks for the idea. I tried this, but it didn't make any difference, even after clearing caches etc. Edit: I figured it out. In the script I "called" the API with this: $initAuth = new ApiAuth(); When I should have used: $initAuth = new Mautic\Auth\ApiAuth(); To "declare" (?) the namespace.
  21. I am trying to connect with an external API, from marketing automation application Mautic on the same server, from a template in Processwire, with something like this: require '/serverpath/vendor/autoload.php'; use Mautic\Auth\ApiAuth; use Mautic\MauticApi; $initAuth = new ApiAuth(); This works in an empty test page outside of Processwire. Trying to use it from a template within Processwire I get this error: How can I make sure the script looks for Mautic's ApiAuth in the correct place? Mautic's autoload.php is included in the page successfully; I have checked that.
  22. I don't think my template code has anything to do with it. Here is a minimal version of the template that still has the same problem: Not only ""/>" is inserted in the html output. When I add a link to my $page->summary field, all the text after the <a href=...> opening tag is copied (?) and inserted after the body tag with most of the head including <title>. I say copied, because the block of text with URL also appears in the correct place. When I remove the link from 'summary', everything looks as it should, no crap inserted after the body tag. Edit: I found it. I had the following in head: <meta name="description" content="<?php echo $page->summary; ?>" /> That works fine with plain text, but breaks when you add html like a URL to the summary field. Or is there a proper way to filter it for meta content?
  23. Adding a URL in a textarea field leaves a random ""/>" in my html output, like: "" /> " Has anyone else seen something like that? What could cause this? Turning off experimental HTML OPTIONS did not fix it.
  24. Uninstall of this module doesn't work: I only installed it, because module refresh gave a warning about a missing file from NewsletterSubscription - probably left-over from another install/uninstall attempt long time ago. Is there another safe way to remove/uninstall modules?
  25. Thanks @ukyo, but what is that supposed to do? I plan to have my custom files in templates/forms. What difference would putting them in templates/extend or site/src make? Why site/src - is adding folders outside templates a good idea? Those classLoader lines apply to the entire folder, not a specific file? Are the general principles how to work with classes and customize modules in Processwire explained anywhere? I haven't been able to find it. This produces a result: CommentListCustom.php copied from the wire module into my templates/inc folder. The custom file is now used to display the comments. I can now make edits in that file to somehow change {cite} to the commenter's full name. Wtf is {cite} anyway? It's not a PHP variable. How is it defined? How can I redefine it? I can't do something like {cite} = $users->get({cite})->fullname; What syntax should I use? What rules apply to these {something} "thingies"? Why does this produce Fatal Error Uncaught Error: Call to a member function get() on null? This seems to work though: For the form it works the same of course: Then make edits in CommentFormCustom.php as required. In my case I added 'hidden' to the cite and email input fields, so logged-in users only get a text field, don't have to enter any other info - the module enters logged-in user name and email in the hidden fields if you remove/turn off all the cookie stuff. Two next issues to solve: 1. Is the upvote/downvote system cookie-based? What would it take to turn that into logged-in user ID-based? Or is that the default if I turn off cookies/remove cookie javascript? 2. Users will expect a way to delete and edit their comments. Has anyone done that? Suggestions welcome.
  • Create New...