JayGee Posted December 16, 2020 Posted December 16, 2020 I'm thinking of using the comments fieldtype for a very basic support ticket system for a project. I guess I can just hide the fields and populate them using JS or something - I'm just wondering if it's possible out the box to disable the name/email fields and use the current logged in users as the comment poster instead without hacking at it. ?
JayGee Posted December 16, 2020 Author Posted December 16, 2020 I've just realised the default form already renders with the current logged in user name and email... so I guess my revised question is can we disable these fields rather than just hide them?
netcarver Posted December 16, 2020 Posted December 16, 2020 I don't think you can prevent the output of those fields - but there is a trick you can pull to prevent them being editable (as well as hiding them using a CSS rule on the wrap classes.) If you override the preset values - but to the same strings as the preset would use anyway - then the form renders them with the disabled attribute. Like this.. <?php echo $page->comments->renderForm([ 'presets' => [ 'cite' => $user->name, 'email' => $user->email, ], ]); I haven't verified, but I believe that the comments fieldtype will replace any tampered fields in the posted form with the original preset, so this might work for you. 1 2
JayGee Posted December 16, 2020 Author Posted December 16, 2020 7 minutes ago, netcarver said: I don't think you can prevent the output of those fields - but there is a trick you can pull to prevent them being editable (as well as hiding them using a CSS rule on the wrap classes.) If you override the preset values - but to the same strings as the preset would use anyway - then the form renders them with the disabled attribute. Like this.. <?php echo $page->comments->renderForm([ 'presets' => [ 'cite' => $user->name, 'email' => $user->email, ], ]); I haven't verified, but I believe that the comments fieldtype will replace any tampered fields in the posted form with the original preset, so this might work for you. Sweet, thanks, works perfectly! I knew there had to be a non-destructive preset in there. You just saved me having to pour through the module classes ? 1
JayGee Posted December 17, 2020 Author Posted December 17, 2020 Hijacking my own thread here lol... but now I think about it more it would be cool to allow images in the comments but looks likes this might be more complex. Might need to switch to an API/repeater based solution and use a CKeditor text field... unless anyone else has a solution/ideas around the comments field?
sjaaksken Posted June 17, 2021 Posted June 17, 2021 Had the same issue but indeed the solution works! Thanks for this! 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now