1

Is it possible to add custom form fields to the EE comment form? What I would like to do is to require people to be logged in members to post but allow them to comment anonymously.

If I add a checkbox with a "Reply Anonymously" option it doesn't record the checkbox state in the exp_comments table.

2 Answers 2

1

You cannot use custom fields in the comment form but you can repurpose any of the native fields to use as needed.

You might look at repurposing the "location" or "url" field and passing your value to that column in the database..

9
  • It seems that if you are logged in, the only field that can be written to in a comment form is the comment text area. Repurposing the other fields doesn't seem to have any effect. Mar 5, 2013 at 20:00
  • That doesn't sound correct. Post the code you are testing to pastie.org
    – Anna_MediaGirl
    Mar 5, 2013 at 20:38
  • Hi Anna - it's at http://pastie.org/6412039. Mar 7, 2013 at 15:11
  • So the checkbox just isn't working at all meaning you can't check it or you can check it but the data isn't passing to the DB?
    – Anna_MediaGirl
    Mar 7, 2013 at 18:32
  • You can check it but the data isn't passed into the DB. Mar 7, 2013 at 18:46
1

Sweet, after checking Devot-ee (why didn't I look there first) I found a recent addon called 'Custom comment fields' (http://devot-ee.com/add-ons/custom-comment-fields) which allows you to add some simple custom fields (Text input, Textarea, Safecracker File) to EE comments module posts. I then used this as a way to add the ability for logged in users to specify if there wished to post a specific comment anonymously.

I added a new custom field using this addon called {comment_anonymously} and then set this as a checkbox field in the {exp:comment:form}

<label>
    <input type="checkbox" name="comment_anonymously" value="y" /> 
    Post my comment anonymously
</label>

Then in the {exp:comment:entries} loop, I used a conditional on the custom comment field to display the users name or not:

Posted by 
{if '{comment_anonymously}' == 'y'}
    Anonymous 
    {if logged_in_group_id == '1'}
        (<em>{name}</em>)
    {/if}
{if:else}
    {name}
{/if}

Note that I've also placed in a conditional for if a Super Admin is looking to show the users actual name for easy verification.

Cheers Brendan

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.