07-20-2023, 01:33 PM
I want to set up a form that allows users to upload files (pdf, jpeg, docx, etc) from outside the Wagtail admin panel. But the form leaves the filefield out on my html page. Any advice would be great thanks!
#models.py
class FormField(AbstractFormField):
page = ParentalKey('FormPage',
related_name='form_fields')
class FormPage(AbstractEmailForm):
template = "formsubmission.html"
file = models.FileField(upload_to='uploads/',
blank=True, null=True)
submit_success = models.CharField(max_length=100,
blank=False, null=True)
submit_error = models.CharField(max_length=100,
blank=False, null=True)
content_panels = AbstractEmailForm.content_panels + [
FieldPanel('submit_success'),
FieldPanel('submit_error'),
InlinePanel('form_fields', label='Form Fields'),
FieldPanel('file')
]
#htmlpage.html
{% extends 'base.html' %}
{% load wagtailcore_tags %}
{% load static %}
{% block content %}
<h1>page.title</h1>
<div class="container">
<form action="{% pageurl page %}" method="POST">
{% csrf_token %}
{{form.as_p}}
<input type="submit">
</form>
{% endblock %}
#models.py
class FormField(AbstractFormField):
page = ParentalKey('FormPage',
related_name='form_fields')
class FormPage(AbstractEmailForm):
template = "formsubmission.html"
file = models.FileField(upload_to='uploads/',
blank=True, null=True)
submit_success = models.CharField(max_length=100,
blank=False, null=True)
submit_error = models.CharField(max_length=100,
blank=False, null=True)
content_panels = AbstractEmailForm.content_panels + [
FieldPanel('submit_success'),
FieldPanel('submit_error'),
InlinePanel('form_fields', label='Form Fields'),
FieldPanel('file')
]
#htmlpage.html
{% extends 'base.html' %}
{% load wagtailcore_tags %}
{% load static %}
{% block content %}
<h1>page.title</h1>
<div class="container">
<form action="{% pageurl page %}" method="POST">
{% csrf_token %}
{{form.as_p}}
<input type="submit">
</form>
{% endblock %}