Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to set enctype="multipart/form-data" on custom CP forms #1665

Closed
lindseydiloreto opened this issue Apr 24, 2017 · 6 comments
Closed
Assignees
Labels
enhancement improvements to existing features

Comments

@lindseydiloreto
Copy link
Contributor

lindseydiloreto commented Apr 24, 2017

We've got a custom plugin which has several back-end pages. On one of these pages, we've created a small form which allows admins to send short messages.

Recently, I've been asked to add attachments to this form. It nearly works perfectly, with only one shortcoming... the form is missing the enctype="multipart/form-data" attribute.

Like most back-end pages, this page extends _layouts/cp. We're using the fullPageForm = true variable to denote that the entire page should behave as a single form. Here is the Craft code which opens the form tag...

<form id="container" method="post" accept-charset="UTF-8" ... >

You'll notice that enctype="multipart/form-data" is conspicuously absent (as it should be for 99% of back-end forms). Unfortunately, this is one of the rare cases where we need that attribute to exist.

Feature Request

Just as we have a fullPageForm variable, could we also have an allowUploads variable?

{% set fullPageForm = true %}
{% set allowUploads = true %}

That would be sweet!

Internally, Craft would simply apply enctype="multipart/form-data" according to whether or not allowUploads is set to true.

Thanks guys! Let me know if you need any clarification! :)

Additional info

  • Craft version: 2.6.2968
@lindseydiloreto
Copy link
Contributor Author

FWIW, I've hacked my local copy to allow this. But hacking the core is obviously not a good long-term solution.

@brandonkelly
Copy link
Member

Took it in a different direction, but the next release has a change that will make this possible: All of the #container HTML attributes are now defined in a containerAttributes block, so you can do this from your sub-template:

{% block containerAttributes -%}
    {{ parent() }} enctype="multipart/form-data"
{%- endblock %}

@lindseydiloreto
Copy link
Contributor Author

Brilliant! Thanks Brandon!

@lindseydiloreto
Copy link
Contributor Author

Just implemented this... works perfectly. 👍

@matt-adigital
Copy link

Does this still exist in Craft 3? Just tried it and it didn't seem to work. Can this functionality be re added please so I can create a form within a cp section which submits files, e.g. screenshots of an issue. Thank you.

brandonkelly added a commit that referenced this issue Nov 8, 2018
@brandonkelly
Copy link
Member

@matt-adigital Yeah looks like that never made it to Craft 3. Just added a new mainFormAttributes block to _layouts/cp.html for the next release.

@brandonkelly brandonkelly added the enhancement improvements to existing features label Mar 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement improvements to existing features
Projects
None yet
Development

No branches or pull requests

4 participants