Skip to content

Instantly share code, notes, and snippets.

@DavidStrada
Last active June 6, 2019 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidStrada/3e2b96664c716a0b4050d352bc7cd4a9 to your computer and use it in GitHub Desktop.
Save DavidStrada/3e2b96664c716a0b4050d352bc7cd4a9 to your computer and use it in GitHub Desktop.
upload file / submit form via Vuejs Statamic
<div class="my-4">
<div class="row">
<div class="col-12">
<div class="my-4">
{{ content }}
</div>
<div class="my-4 ">
{{# Needed Crypt Lib. #}}
<upload-file param="<?php echo Crypt::encrypt(['formset'=> 'uploadFile']) ?>"
message="{{ thank-you-note }}">
</upload-file>
</div>
</div>
</div>
</div>
title: 'File Uploader'
store: false
fields:
file:
type: asset
container: main
folder: uploads
columns:
- file
<template>
<form action="#" @submit.prevent="submitForm">
<div class="form-group">
<label for="my-input">Text</label>
<input
id="my-input"
class="form-control"
type="file"
ref="fileUpload"
@change="handleFileUpload"
/>
</div>
<button type="submit">send</button>
</form>
</template>
<script>
import axios from 'axios'
export default {
name: 'UploadFile',
props: {
param: String,
message: String,
},
data() {
return {
form: {
file: null,
_params: this.param,
},
}
},
methods: {
handleFileUpload() {
console.log('here file upload', this.$refs.fileUpload.files[0])
this.form.file = this.$refs.fileUpload.files[0]
},
submitForm() {
let formData = new FormData()
formData.append('file', this.form.file)
formData.append('_params', this.param)
axios
.post('/!/Form/create', formData, {
headers: {
'Content-Type': 'multipart/form-data',
},
})
.then(function() {
console.log('SUCCESS!!')
})
.catch(function() {
console.log('FAILURE!!')
})
},
},
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment