MG 2.3 How to create a NSFW consent checkbox for a Media Gallery Category?

Arun Kumar

Member
Hello XenForo community,

I'm trying to implement a consent checkbox for adult/NSFW content in my XenForo Media Gallery (XFMG), but I'm running into some limitations with the available field types.

Current setup:
I've created a custom media field with these settings:
  • Field ID: adult
  • Title: Adult Content Notice
  • Display location: Below media item
  • Applicable categories: Adult Art (and other relevant categories)

The issue:
When configuring the field type, I only see these options:
  • Single-line text box
  • Multi-line text box
  • Rich text box

There doesn't appear to be any option for checkboxes or radio buttons in the media field types, unlike what might be available in other areas of XenForo.

What I've attempted:
I tried using a single-line text box with custom Value display HTML to simulate a checkbox:

Code:
<label class="nsfw-consent">
  <input type="checkbox" id="nsfw_consent_{$fieldId}" class="nsfw-checkbox" {if $value == 'accepted'}checked="checked"{/if} onclick="document.getElementById('nsfw_text_{$fieldId}').value = this.checked ? 'accepted' : '';">
  I acknowledge this media contains adult content
</label>
<input type="hidden" id="nsfw_text_{$fieldId}" name="custom_fields[{$fieldId}]" value="{$value}">

And Wrapper display HTML:
Code:
<div class="adultContentNotice">
  <div class="adultWarningTitle">Adult Content Notice</div>
  {$value}
</div>

Unfortunately, this workaround didn't function as expected.

What I'm trying to accomplish:
I need a way for users to acknowledge they're viewing adult content before seeing media in certain categories. Specifically:
1. A checkbox that users must check to acknowledge adult content
2. This should only apply to specific categories (like "Adult Art")
3. Ideally, the content would be blurred/hidden until the checkbox is clicked

Questions:
1. Are there additional field types available for Media Gallery that I'm missing?
2. Is there an add-on that extends the available field types for XFMG?
3. What's the recommended approach for implementing NSFW consent in the Media Gallery?
4. Would a custom template modification be more appropriate for this use case?

Any guidance would be greatly appreciated!
 
Last edited:
It would be much easier with user preferences, user groups, and user group promotions with permissions on a "NSFW" category (and a notice for that category to enable NSFW in user preferences if they want to view it).

That is unless you allow NSFW to be posted in any category.
 
But can also be done with template edits to hide images that are NSFW a value is set to Yes. I had to spin up XFMG because
The issue:
When configuring the field type, I only see these options:
  • Single-line text box
  • Multi-line text box
  • Rich text box
This didn't seem right to me.

1741934340910.webp

ACP: admin.php?media-gallery/fields/add
 
Radio boxes for Yes/No set to required:
1741934517220.webp

The template xfmg_media_view would need to be edited (amongst others that might show the thumbnail) with an <xf:if> conditional to blur the image, black it out, or do an overlay if it's set to Yes (when a user's preference [with user group upgrades to a NSFW group] is set to No).
 
Back
Top Bottom