fix the form wizard
This commit is contained in:
parent
a23c96cc17
commit
a0d09feaef
Binary file not shown.
Binary file not shown.
@ -25,7 +25,7 @@ SECRET_KEY = 'django-insecure-_!ew&)1&r--3h17knd27^x8(xu(&-f4q3%x543lv5vx2!784s*
|
|||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
|
|
||||||
ALLOWED_HOSTS = []
|
ALLOWED_HOSTS = ["*"]
|
||||||
|
|
||||||
# Application definition
|
# Application definition
|
||||||
|
|
||||||
|
|||||||
@ -16,15 +16,23 @@ urlpatterns = [
|
|||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
path('api/', include(router.urls)),
|
path('api/', include(router.urls)),
|
||||||
path('accounts/', include('allauth.urls')),
|
path('accounts/', include('allauth.urls')),
|
||||||
path('i18n/', include('django.conf.urls.i18n')),
|
path('i18n/', include('django.conf.urls.i18n')),
|
||||||
path('summernote/', include('django_summernote.urls')),
|
path('summernote/', include('django_summernote.urls')),
|
||||||
|
# path('', include('recruitment.urls')),
|
||||||
|
path('<int:template_id>/', views.form_wizard_view, name='form_wizard'),
|
||||||
|
path('<int:template_id>/submit/', views.submit_form, name='submit_form'),
|
||||||
|
|
||||||
|
path('api/templates/', views.list_form_templates, name='list_form_templates'),
|
||||||
|
path('api/templates/save/', views.save_form_template, name='save_form_template'),
|
||||||
|
path('api/templates/<int:template_id>/', views.load_form_template, name='load_form_template'),
|
||||||
|
path('api/templates/<int:template_id>/delete/', views.delete_form_template, name='delete_form_template'),
|
||||||
]
|
]
|
||||||
|
|
||||||
# 2. URLs that DO have a language prefix (user-facing views)
|
|
||||||
# This includes the root path (''), which is handled by 'recruitment.urls'
|
|
||||||
urlpatterns += i18n_patterns(
|
urlpatterns += i18n_patterns(
|
||||||
path('', include('recruitment.urls')),
|
path('', include('recruitment.urls')),
|
||||||
)
|
)
|
||||||
|
# 2. URLs that DO have a language prefix (user-facing views)
|
||||||
|
# This includes the root path (''), which is handled by 'recruitment.urls'
|
||||||
|
|
||||||
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||||
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
||||||
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -61,15 +61,11 @@ urlpatterns = [
|
|||||||
path('forms/', views.form_templates_list, name='form_templates_list'),
|
path('forms/', views.form_templates_list, name='form_templates_list'),
|
||||||
path('forms/create-template/', views.create_form_template, name='create_form_template'),
|
path('forms/create-template/', views.create_form_template, name='create_form_template'),
|
||||||
|
|
||||||
path('forms/form/<int:template_id>/', views.form_wizard_view, name='form_wizard'),
|
# path('forms/form/<int:template_id>/submit/', views.submit_form, name='submit_form'),
|
||||||
path('forms/form/<int:template_id>/submit/', views.submit_form, name='submit_form'),
|
# path('forms/form/<int:template_id>/', views.form_wizard_view, name='form_wizard'),
|
||||||
path('forms/<int:form_id>/submissions/<int:s>/', views.form_submission_details, name='form_submission_details'),
|
path('forms/<int:form_id>/submissions/<int:slug>/', views.form_submission_details, name='form_submission_details'),
|
||||||
path('forms/template/<slug:slug>/submissions/', views.form_template_submissions_list, name='form_template_submissions_list'),
|
path('forms/template/<slug:slug>/submissions/', views.form_template_submissions_list, name='form_template_submissions_list'),
|
||||||
|
|
||||||
path('api/templates/', views.list_form_templates, name='list_form_templates'),
|
|
||||||
path('api/templates/save/', views.save_form_template, name='save_form_template'),
|
|
||||||
path('api/templates/<int:template_id>/', views.load_form_template, name='load_form_template'),
|
|
||||||
path('api/templates/<int:template_id>/delete/', views.delete_form_template, name='delete_form_template'),
|
|
||||||
# path('forms/<int:form_id>/', views.form_preview, name='form_preview'),
|
# path('forms/<int:form_id>/', views.form_preview, name='form_preview'),
|
||||||
# path('forms/<int:form_id>/submit/', views.form_submit, name='form_submit'),
|
# path('forms/<int:form_id>/submit/', views.form_submit, name='form_submit'),
|
||||||
# path('forms/<int:form_id>/embed/', views.form_embed, name='form_embed'),
|
# path('forms/<int:form_id>/embed/', views.form_embed, name='form_embed'),
|
||||||
|
|||||||
@ -33,6 +33,7 @@ from .utils import (
|
|||||||
get_available_time_slots,
|
get_available_time_slots,
|
||||||
)
|
)
|
||||||
from django.views.decorators.csrf import ensure_csrf_cookie
|
from django.views.decorators.csrf import ensure_csrf_cookie
|
||||||
|
from django.views.decorators.http import require_POST
|
||||||
from .models import (
|
from .models import (
|
||||||
FormTemplate,
|
FormTemplate,
|
||||||
FormStage,
|
FormStage,
|
||||||
@ -814,10 +815,14 @@ def form_wizard_view(request, template_id):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@require_http_methods(["GET", "POST"])
|
@require_POST
|
||||||
def submit_form(request, template_id):
|
def submit_form(request, template_id):
|
||||||
"""Handle form submission"""
|
"""Handle form submission"""
|
||||||
print("request method", request.method)
|
print(f"Request method: {request}")
|
||||||
|
print(f"CSRF token in POST: {'csrfmiddlewaretoken' in request.POST}")
|
||||||
|
print(f"CSRF token value: {request.POST.get('csrfmiddlewaretoken', 'NOT FOUND')}")
|
||||||
|
print(f"POST data: {request.POST}")
|
||||||
|
print(f"FILES data: {request.FILES}")
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
try:
|
try:
|
||||||
template = get_object_or_404(FormTemplate, id=template_id)
|
template = get_object_or_404(FormTemplate, id=template_id)
|
||||||
|
|||||||
@ -876,11 +876,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
|
|
||||||
|
// Add CSRF token as a form field (CRITICAL FIX)
|
||||||
formData.append('csrfmiddlewaretoken', csrfToken);
|
formData.append('csrfmiddlewaretoken', csrfToken);
|
||||||
// Add applicant info
|
|
||||||
//formData.append('applicant_name', state.formData.applicant_name || '');
|
|
||||||
//formData.append('applicant_email', state.formData.applicant_email || '');
|
|
||||||
console.log(state.formData)
|
|
||||||
// Add field responses
|
// Add field responses
|
||||||
state.stages.forEach(stage => {
|
state.stages.forEach(stage => {
|
||||||
stage.fields.forEach(field => {
|
stage.fields.forEach(field => {
|
||||||
@ -898,22 +897,35 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/forms/form/${state.templateId}/submit/`, {
|
const response = await fetch(`/${state.templateId}/submit/`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: formData
|
body: formData
|
||||||
|
// IMPORTANT: Do NOT set Content-Type header when using FormData
|
||||||
|
// Do NOT set X-CSRFToken header when using csrfmiddlewaretoken in form data
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = await response.json();
|
// Check if response is OK
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`HTTP error! status: ${response.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
alert('Application submitted successfully! Thank you for your submission.');
|
alert('Application submitted successfully! Thank you for your submission.');
|
||||||
window.location.href = '/templates/'; // Redirect to templates list
|
window.location.href = '/applications/'; // Redirect to applications list
|
||||||
} else {
|
} else {
|
||||||
alert('Error submitting form: ' + result.error);
|
alert('Error submitting form: ' + (result.error || 'Unknown error'));
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error:', error);
|
console.error('Submission error:', error);
|
||||||
alert('Error submitting form. Please try again.');
|
// Try to get response text for debugging
|
||||||
|
try {
|
||||||
|
const errorText = await response.text();
|
||||||
|
console.error('Response text:', errorText);
|
||||||
|
alert('Error submitting form. Server response: ' + errorText);
|
||||||
|
} catch (e) {
|
||||||
|
alert('Error submitting form: ' + error.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -953,7 +965,7 @@
|
|||||||
elements.nextBtn.style.display = 'flex';
|
elements.nextBtn.style.display = 'flex';
|
||||||
elements.nextBtn.textContent = state.currentStage === state.stages.length - 1 ?
|
elements.nextBtn.textContent = state.currentStage === state.stages.length - 1 ?
|
||||||
'Preview' :
|
'Preview' :
|
||||||
'Next'
|
'Next'
|
||||||
}
|
}
|
||||||
|
|
||||||
function createFieldElement(field) {
|
function createFieldElement(field) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user