0

I've got A&M forms set up and I'm trying to get a assets field to upload files.

My current form code is below. If I remove the first line then the form works correctly but I can't get a file upload to work without it as I am unable to figure out how to manually code the file upload field.

My current commented out code for the file was cribbed from a previous ExpressionEngine install and uses some Javascript to allow styling of the field. Everything seems to work here as I can upload a file but due to the internal server error on submit I can't be sure.

Without line 1 the form works but I can't get file uploads. How do I resolve this?

{% set form = craft.amForms.getForm('requestQuote') %}


<form method="post" accept-charset="UTF-8" class="form-horizontal contact-form">
{# This should always be here! #}
<input type="hidden" name="action" value="amForms/submissions/saveSubmission">

{# Insert your forms handle. #}
<input type="hidden" name="handle" value="requestQuote">

{# Optional: Redirect URL. Will redirect to current page by default. #}
<input type="hidden" name="redirect" value="contact/thankyou">

{# Optional: Anti-spam protection. #}
  {{ craft.amForms.displayAntispam() }}

  {# Optional: Google reCAPTCHA protection. #}
  {{ craft.amForms.displayRecaptcha() }}

  <fieldset class="row">

    <div class="col-sm-6">
        <label class="sr-only control-label" for="textinput">Name</label>
        <input id="name" name="fields[fullName]" type="text" placeholder="Name" class="form-control input-md" required>

    </div>

    <div class="col-sm-6">
        <label class="sr-only control-label" for="Email">Email</label>
        <input id="email" name="fields[emailAddress]" type="email" placeholder="Email" class="form-control input-md" required>

    </div>

    <div class="col-sm-6">
        <label class="sr-only control-label" for="phone">Phone</label>
        <input id="phone" name="fields[telephoneNumber]" type="text" placeholder="Phone" class="form-control input-md">
    </div>

    <div class="col-sm-6">
        <label class="sr-only control-label" for="companyName">Company Name</label>
        <input id="company" name="fields[companyName]" type="text" placeholder="Company Name" class="form-control input-md">
    </div>

    <div class="col-sm-12">
      <label class="sr-only control-label" for="budget">Budget</label>
        <select id="budget" name="fields[budget]" class="form-control" required>
          <option disabled="" selected>expected budget</option>
        <option value="< $2,500">< $2,500</option>
        <option value="$2,500-$5,000">$2,500-$5,000</option>
        <option value="$5,000-$10,000">$5,000-$10,000</option>
        <option value="$10,000-$15,000">$10,000-$15,000</option>
        <option value="> $15,000">>$15,000</option>
        <option value="More Details below">More Details below</option>
        <option value="I'm not sure">I'm not sure</option>
        </select>
    </div>

{#
// commmented out for testing
// unstyled field added below this commented block
    <div class="col-sm-12">
      <span id="changefree">{{ form.displayField('attachment') }}</span>
      <div class="input-group">
        <input type="text" name="fields[attachment][]" id="fields-attachment" class="form-control" disabled placeholder="Upload File">
        <span class="input-group-btn">
          <button class="browse btn btn-default extra-pad" type="button"><i class="glyphicon glyphicon-search"></i> Browse</button>
        </span>
      </div>
    </div>
    #}

    {{ form.displayField('attachment') }}



    <!-- Textarea -->
    <div class="col-sm-12">
      <label class="sr-only control-label" for="projectDetails">Project Details and Message</label>
        <textarea class="form-control" id="project_details" name="fields[projectDetails]" placeholder="Project Details and Message"></textarea>
    </div>

    <!-- Button -->
    <div class="col-sm-12">
      <button id="singlebutton" type="submit" name="singlebutton" class="btn btn-primary">Submit</button>
    </div>

  </fieldset>



</form>
  • The underlying error message for the 500 Internal Server Error is either going to be logged in craft/storage/runtime/logs if Craft generated it, or your web server's error logs if your web server generated it. – Brad Bell Oct 26 '16 at 20:47
  • The server error log is empty on my host but I'm not sure what to look for in the /logs file for Craft. – CreateSean Oct 26 '16 at 20:57
  • Nuke the logs, reproduce the issue, then search for [error] in the craft.log files or in the phperrors.log if you have that one, too. – Brad Bell Oct 26 '16 at 21:15
  • Maybe it helps if you add enctype="multipart/form-data"to the form tag? See (github.com/am-impact/amforms/issues/64) – Wolfram Gehring Oct 26 '16 at 22:25
  • @WolframGehring Can you add that as an answer so I can mark it correct. Thanks. – CreateSean Oct 27 '16 at 16:30
3

If you want to upload assets with your form, you will need to include enctype="multipart/form-data" in your form tag: <form method="post" accept-charset="UTF-8" enctype="multipart/form-data" ...

| improve this answer | |

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.