Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upload file with formspree

Tags:

html

forms

I am trying to allow users on my website to upload an image with a form. I have been using formspree (https://formspree.io/) I receive the name of the image but no image attached to the email.

I'm using:

<label>
    Upload Photo
    <input type="file" name="uploadField" />
</label>

Has anyone managed to do this?

like image 426
nzdavo Avatar asked Sep 06 '15 23:09

nzdavo


2 Answers

Formspree currently doesn't support file inputs, but Formsprees FAQ has this advice:

For almost zero work and cheap (or free) prices you can integrate external file upload services into a Formspree form. Uploadcare is one example. If you just create an account and include their widget:

<!-- The best place for this one is your <HEAD> tag -->
<script>UPLOADCARE_PUBLIC_KEY = "demopublickey";</script>
<script 
src="https://ucarecdn.com/libs/widget/3.x/uploadcare.full.min.js" 
charset="utf-8"></script>

<!-- This is where the widget will be. Don't forget the name attribute! -->
<input type="hidden" role="uploadcare-uploader" name="my_file" />

Per their documentation, you can use that inside the Formspree form and receive the URL of the document in your email address.

Source: https://help.formspree.io/articles/6199-how-to-do-file-uploads-with-formspree

like image 118
sandstrom Avatar answered Nov 15 '22 11:11

sandstrom


I'm pretty sure the issue is your enctype isn't defined. Here's an example using a basic HTML form (you'll need some PHP/server side code to process the file):

<form action="your_script.php" method="post" enctype="multipart/form-data">
   Image: <input type="file" name="uploadField" />
  <input type="submit" value="Submit">
</form>
like image 42
ScottMcGready Avatar answered Nov 15 '22 12:11

ScottMcGready