1

I'm currently trying to implement a simple file-upload form with CraftCMS.

However, even though there are no errors on submitting the form, no file actually seems to get uploaded.

This is the form:

<form action="" method="post" accept-charset="UTF-8" enctype="multipart/form-data">
        <input type="hidden" name="action" value="entries/saveEntry"/>
        <input type="hidden" name="sectionId" value="29">
        <input type="hidden" name="enabled" value="1">

        <input type="file" name="useruploads" style="margin-bottom: 30px"/>

        <select class="form-control" id="sel1" style="margin-bottom: 30px">
            <option>x-challenge auswählen</option>
            {% for entry in craft.entries.section('challenges') %}
                {% for ch in entry.allOverChallenge %} %}
                    <option>( Tirol ) {{ch.allOverName}}</option>
                {% endfor %}
            {% endfor %}

            {% for entry in craft.entries.section('xSpots') %}
                {% for ch in entry.standaloneChallenges %} %}
                <option>( {{entry.title}} ) {{ch.standaloneName}}</option>
                {% endfor %}
            {% endfor %}
        </select>

        <input type="text" class="form-control" id="challenge_select" placeholder="Titel eingeben" style="margin-bottom: 30px">

        <textarea class="form-control" rows="5" id="challenge_description" placeholder="Beschreibung eingeben" style="margin-bottom: 30px"></textarea>

        <input type="text" class="form-control" id="challenge_customtags" placeholder="Hashtags ( max. 3 )" style="margin-bottom: 30px">
        <div style="margin-bottom: 30px">
            <input type="reset" value="abbrechen">
            <input type="submit" value="hochladen">
        </div>
    </form>



I'm attaching two screenshots that show both the actual field and the section:

enter image description here enter image description here

When submitting the form in it's current state, no entries actually get added to the field as shown in the image below. Am I doing something wrong here? I'd appreciate some help on the topic.

enter image description here

2 Answers 2

2

Have you tried enabling devMode in the craft/config/general.php file? You can do this by adding 'devMode' => true to the array. You should then be able to see an error on submission.

If this fails to output anything then it could be that your input requires square brackets adding to the name, e.g. name="useruploads[]"

Even though you have limited the field to 1 upload, it may still be expecting an array to be posted to it.

2

Doesn't look like the field name is correct - you should be using the fields namespace for all the actual Entry fields. For the upload, for example, you should be using fields[useruploads].

You can find more information about Asset uploads specifically here

1
  • That actually did the trick. The file now uploads to the assets. However, the files are still not added to the field referenced by fields[useruploads]. Is this even possible? Commented Apr 13, 2017 at 12:13

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.