7

I'm using Craft Guest Entries plugin and the Entry Form technique elsewhere on my site. I'm currently trying to add a file upload to it. The entry is publishing but nothing is making it to assets.

Here's the code:

<form class="ajax-form" method="post" action="" enctype="multipart/form-data" accept-charset="UTF-8">
    <input type="hidden" name="action" value="guestEntries/saveEntry">
    <input type="hidden" name="sectionId" value="17">
    <input type="hidden" name="enabled" value="1">
    <input type="hidden" name="fields[whitepaperCategory]" value="{{entry.title}}">

    <label for="name">Name</label>
    <input type="text" id="name" name="title" required>

    <label for="email">Email Address</label>
    <input type="email" id="email" name="fields[email]" required>

    <label for="resume">Resume and Cover Letter (.pdf)</label>
    <div class="file-upload btn btn-primary">
        <span>Upload Resume and Cover Letter</span>
        <input type="file" id="resume" name="fields[resumes][]" class="upload" multiple>
    </div>

    <button type="submit" class="btn btn-submit">Submit</button>
</form>

Is there anything obvious I'm missing?

8
  • So, uhh, how does Ajax come in play here? Jul 30 '14 at 19:11
  • Well I'm submitting the form using AJAX, which is working for all my forms that don't have file uploads. The form is submitting here as well, but the file input is not making it to Craft. I took AJAX out of the picture earlier and I'm having the same problem, so maybe it isn't AJAX's fault. Jul 30 '14 at 19:31
  • Something might be failing validation. Make sure devMode is enabled, reproduce it and see if anything gets logged with [error] or [warning] in your craft/storage/runtime/logs files.
    – Brad Bell
    Jul 30 '14 at 19:57
  • There are some errors but none that are timestamped near any of my form submissions. I submitted the form a few times and nothing new has shown up. Jul 30 '14 at 21:02
  • I may have misunderstood something (particularly as Brad has already commented on this), but in this answer, Brad seems to be stating that the Guest Entries plugin cannot process file uploads. Aug 12 '14 at 20:19
4
+50

I just tested this locally and it's working fine (with the caveat that the latest build 2.1.2568 introduced a separate, unrelated bug that broke front-end asset uploading that's been fixed in build 2.1.2569).

Most likely something is failing validation when the entry is saving.

Try using this to see if there are any errors:

<form class="ajax-form" method="post" action="" enctype="multipart/form-data" accept-charset="UTF-8">

    {% macro errorList(errors) %}
        {% if errors %}
            <ul class="errors">
                {% for error in errors %}
                    <li>{{ error }}</li>
                {% endfor %}
            </ul>
        {% endif %}
    {% endmacro %}

    {% from _self import errorList %}

    <input type="hidden" name="action" value="guestEntries/saveEntry">
    <input type="hidden" name="sectionId" value="17">
    <input type="hidden" name="enabled" value="1">
    <input type="hidden" name="fields[whitepaperCategory]" value="{{entry.title}}">

    <label for="name">Name</label>
    <input type="text" id="name" name="title" required>

    {% if entry is defined %}
        {{ errorList(entry.getErrors('title')) }}
    {% endif %}

    <label for="email">Email Address</label>
    <input type="email" id="email" name="fields[email]" required>

    {% if entry is defined %}
        {{ errorList(entry.getErrors('email')) }}
    {% endif %}

    <label for="resume">Resume and Cover Letter (.pdf)</label>
    <div class="file-upload btn btn-primary">
        <span>Upload Resume and Cover Letter</span>
        <input type="file" id="resume" name="fields[resumes][]" class="upload" multiple>
    </div>

    {% if entry is defined %}
        {{ errorList(entry.getErrors('resumes')) }}
    {% endif %}

    <button type="submit" class="btn btn-submit">Submit</button>
</form>
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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