|
| 1 | +<template> |
| 2 | + <section class="hero is-info"> |
| 3 | + <div class="container"> |
| 4 | + <div class="box"> |
| 5 | + <div class="hero-body"> |
| 6 | + <div class="feedback"> |
| 7 | + <h1 class="title">Feedback Form</h1> |
| 8 | + <h1>{{ msg }}</h1> |
| 9 | + <br> |
| 10 | + <form v-if="!submitted"> |
| 11 | + <div class="radio-form"> |
| 12 | + <div v-for="radio in radioList" :key="radio.id"> |
| 13 | + <input :name="radio.id" required v-model="formData.selectedOption" type="radio" :id="radio.id" |
| 14 | + :value="radio.id" /> |
| 15 | + <label :for="radio.id">{{ radio.label }}</label> |
| 16 | + </div> |
| 17 | + </div> |
| 18 | + <div class="form-text" v-if="formData.selectedOption === 'what-other'"> |
| 19 | + <label for="otherText">Please specify</label> |
| 20 | + <input type="text" id="otherText" name="otherText" v-model="formData.otherText" size="40"/> |
| 21 | + </div> |
| 22 | + <br> |
| 23 | + <div class="form-text"> |
| 24 | + <label for="tellUsAboutIt">Tell us about it <span aria-label="Required question">*</span></label> |
| 25 | + <textarea name="tellUsAboutIt" id="tellUsAboutIt" v-model="formData.tellUsAboutIt" cols="40" |
| 26 | + rows="4" required></textarea> |
| 27 | + </div> |
| 28 | + <div class="form-text"> |
| 29 | + <label for="howDoYouKnow">How do you know</label> |
| 30 | + <textarea name="howDoYouKnow" id="howDoYouKnow" v-model="formData.howDoYouKnow" cols="40" |
| 31 | + rows="2" size="40"></textarea> |
| 32 | + </div> |
| 33 | + <div class="form-text"> |
| 34 | + <label for="thePageWhereItHappened">The page where it happened</label> |
| 35 | + <input type="text" id="thePageWhereItHappened" name="thePageWhereItHappened" |
| 36 | + v-model="formData.thePageWhereItHappened" size="40"/> |
| 37 | + </div> |
| 38 | + <div class="form-text"> |
| 39 | + <label for="yourEmail">Your email</label> |
| 40 | + <input type='text' id='yourEmail' name='yourEmail' v-model="formData.yourEmail" size="40"/> |
| 41 | + </div> |
| 42 | + <br> |
| 43 | + <div class="form-text"> |
| 44 | + <button :disabled="noInput" class="button is-primary is-small" type="submit" |
| 45 | + @click.prevent="submitFormPost">Submit |
| 46 | + Feedback</button> |
| 47 | + </div> |
| 48 | + </form> |
| 49 | + </div> |
| 50 | + </div> |
| 51 | + </div> |
| 52 | + </div> |
| 53 | + </section> |
| 54 | +</template> |
| 55 | + |
| 56 | +<script> |
| 57 | +import axios from 'axios' |
| 58 | +export default { |
| 59 | + name: 'Feedback', |
| 60 | + data () { |
| 61 | + return { |
| 62 | + submitted: false, |
| 63 | + msg: 'What happened?', |
| 64 | + radioList: [ |
| 65 | + { id: 'what-wrong', label: 'Something went wrong' }, |
| 66 | + { id: 'what-suggest', label: 'I have a suggestion' }, |
| 67 | + { id: 'what-error', label: 'I found a content or data error' }, |
| 68 | + { id: 'what-confused', label: 'Something is confusing' }, |
| 69 | + { id: 'what-nice', label: 'Nothing, I just want to say something nice' }, |
| 70 | + { id: 'what-other', label: 'Other' } |
| 71 | + ], |
| 72 | +
|
| 73 | + formData: { |
| 74 | + selectedOption: 'what-suggest', |
| 75 | + otherText: '', |
| 76 | + tellUsAboutIt: '', |
| 77 | + howDoYouKnow: '', |
| 78 | + thePageWhereItHappened: '', |
| 79 | + yourEmail: '' |
| 80 | + } |
| 81 | + } |
| 82 | + }, |
| 83 | + mounted () { |
| 84 | + if (this.$route.query.selectedOption) { |
| 85 | + this.formData.selectedOption = this.$route.query.selectedOption |
| 86 | + } |
| 87 | + if (this.$route.query.thePage) { |
| 88 | + this.formData.thePageWhereItHappened = this.$route.query.thePage |
| 89 | + } |
| 90 | + if (this.$route.query.defaultValue) { |
| 91 | + this.formData.tellUsAboutIt = this.$route.query.defaultValue |
| 92 | + } |
| 93 | + }, |
| 94 | + computed: { |
| 95 | + formParams () { |
| 96 | + const selectedRadio = this.radioList.find(radio => radio.id === this.formData.selectedOption) |
| 97 | + const params = { |
| 98 | + submit: 'Submit', |
| 99 | + 'entry.843445704': this.formData.tellUsAboutIt, |
| 100 | + 'entry.584749072': this.formData.howDoYouKnow, |
| 101 | + 'entry.1794541886': this.formData.thePageWhereItHappened, |
| 102 | + 'entry.1040622557': this.formData.yourEmail, |
| 103 | + 'entry.852279778': Date.now().toString() |
| 104 | + } |
| 105 | +
|
| 106 | + if (selectedRadio) { |
| 107 | + const entryId = 'entry.564578111' |
| 108 | + if (selectedRadio.id === 'what-other') { |
| 109 | + params[entryId] = '__other_option__' |
| 110 | + params[`${entryId}.other_option_response`] = this.formData.otherText |
| 111 | + } else { |
| 112 | + params[entryId] = selectedRadio.label |
| 113 | + } |
| 114 | + } |
| 115 | + return params |
| 116 | + }, |
| 117 | +
|
| 118 | + noInput () { |
| 119 | + return this.formData.tellUsAboutIt.length === 0 |
| 120 | + }, |
| 121 | + formUrl () { |
| 122 | + return 'https://docs.google.com/forms/d/e/1FAIpQLSf5gGHLck-Uv6WayZjgEYysfLxe_xpPxB9jiB9qv7LWEpbjZg/formResponse' |
| 123 | + } |
| 124 | + }, |
| 125 | + methods: { |
| 126 | + submitFormPost () { |
| 127 | + const bodyFormData = new FormData() |
| 128 | + Object.entries(this.formParams).forEach(([key, value]) => { |
| 129 | + bodyFormData.append(key, value) |
| 130 | + }) |
| 131 | + axios.post(this.formUrl, bodyFormData) |
| 132 | + .catch(function (error) { |
| 133 | + console.log(error) |
| 134 | + }) |
| 135 | + this.submitted = true |
| 136 | + this.msg = 'Thank you for your feedback!' |
| 137 | + } |
| 138 | + } |
| 139 | +} |
| 140 | +</script> |
| 141 | + |
| 142 | +<style scoped lang="sass"> |
| 143 | +.hero.is-info |
| 144 | + display: flex |
| 145 | + justify-content: center |
| 146 | + align-items: center |
| 147 | + min-height: 100vh |
| 148 | +
|
| 149 | +.container |
| 150 | + max-width: 600px |
| 151 | +
|
| 152 | +.box |
| 153 | + background-color: rgba(255, 255, 255, 0.7) |
| 154 | + border-radius: 8px |
| 155 | + padding: 30px |
| 156 | + box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1), 0 1px 3px rgba(0, 0, 0, 0.08) |
| 157 | +
|
| 158 | +.feedback |
| 159 | + width: 100% |
| 160 | +
|
| 161 | +.form-text label |
| 162 | + display: block |
| 163 | + margin-top: 5px |
| 164 | +
|
| 165 | +.button |
| 166 | + min-width: 250px |
| 167 | + margin-bottom: 15px |
| 168 | +
|
| 169 | +p |
| 170 | + margin-bottom: 15px |
| 171 | +
|
| 172 | +abbr |
| 173 | + border-bottom: dotted 1px #333 |
| 174 | + cursor: help |
| 175 | +</style> |
0 commit comments