Closed moreplavec closed 1 year ago
Can you give a more concrete example i can test/investigate with?
For example i have this form:
product-form-en:
fields:
-
name: name
label: Name
classes: form-control
placeholder: 'Your name'
autofocus: 'on'
autocomplete: 'on'
type: text
validate: { required: true }
-
name: email
label: Email
classes: form-control
placeholder: 'Your email'
type: email
validate: { required: true }
-
name: phone
label: Phone
classes: form-control
placeholder: 'Your phone'
type: text
-
name: message
label: Message
classes: form-control
placeholder: 'Your message or tea you are interested in...'
type: textarea
validate: { required: true }
buttons:
-
type: submit
classes: 'btn btn-primary'
id: odeslat-formular
value: Send
process:
-
email: { subject: '[Site Contact Form] {{ form.value.name|e }}', body: '{% include ''forms/data.html.twig'' %}' }
-
save: { fileprefix: contact-, dateformat: Ymd-His-u, extension: txt, body: '{% include ''forms/data.txt.twig'' %}' }
-
message: 'Thank you. We will contact you shortly.'
But i need insert, for example, field: sended from page {{ page.path }} or {{ header.product.name }} to know from which product page it was sended.
You can add a hidden field that has the option to evaluate the Twig.
So,
-
name: referral
type: hidden
evaluate: true
default: 'page.url'
will generate
<input data-grav-field="hidden" type="hidden" class="input" name="data[referral]" value="/grav-develop/it/form" />
(and will be available in the email body just like any other field for your use)
Thanks for help, i tried, but i get only this in code:
<div class="form-group">
<input data-grav-field="hidden" data-grav-disabled="false" type="hidden" class="input" name="data[referral]" value="">
</div>
Don't know where is the problem, but when i save form in header, instead of default: 'page.url', it's presented as default: page.url when i load it again. I tried to save it via MD editor and the problem stays.
Saved version of email looks like:
name: lkjsdflkj
email: fasdlkfjasd@asdlfkjalsdf.com
phone: asdfasdfasfd
message: asdfasdf
referral:
Works fine for me with:
name:
label: Name
type: hidden
evaluate: true
default: 'page.title'
link:
label: Url
type: hidden
evaluate: true
default: "base_url_absolute ~ page.route"
Nice plugin, but is it possible to send some variables from Grav template? For example, i have simple product request form, but i need to add page path from which page was form sent or some product information, like product name. All data are in the template, but {{ variable }} is not working if used in page header of the MD file.