Jump to content

FieldtypeComments without the email/name field?


Guy Incognito
 Share

Recommended Posts

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. 😃

 

Link to comment
Share on other sites

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.

  • Like 1
  • Thanks 2
Link to comment
Share on other sites

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 😃

  • Like 1
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

  • 5 months later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...