craftcms / contact-form

Add a simple contact form to your Craft CMS site.
https://plugins.craftcms.com/contact-form
MIT License
294 stars 93 forks source link

Conditional File Attachments #194

Closed richhayler closed 8 months ago

richhayler commented 4 years ago

How would one conditionally allow files attachments in the contact form template based on the contact form configuration "allow attachments" being toggled to "true" in the control panel?

e.g. something like this:

{% if craft.app.session.allowAttachments(true) %}
    <input type="file" name="attachment">
{% endif %}
i-just commented 8 months ago

Hi, thanks for reaching out and apologies for the late reply!

You can get plugin settings from twig via: craft.app.plugins.getPlugin('contact-form').getSettings().

So, to check the allowAttachments, you’d need: craft.app.plugins.getPlugin('contact-form').getSettings()['allowAttachments'].