move plan choice into form

This commit is contained in:
Tobias Brunner 2025-03-04 16:49:30 +01:00
parent 928bd0818e
commit aa4ec33c93
No known key found for this signature in database
4 changed files with 56 additions and 7 deletions

View file

@ -54,6 +54,17 @@
{% endif %}
</div>
{% if choices %}
<div class="mb-3">
<label for="id_choice" class="form-label">{{ choice_label|default:"Please Select" }}</label>
<select name="selected_choice" id="id_choice" class="form-control">
{% for choice_id, choice_name in choices %}
<option value="{{ choice_id }}|{{ choice_name }}">{{ choice_name }}</option>
{% endfor %}
</select>
</div>
{% endif %}
<div class="mb-3">
<label for="id_message" class="form-label">Your Message (Optional)</label>
{{ form.message|addclass:"form-control" }}

View file

@ -149,11 +149,6 @@
</div>
{% endif %}
</div>
<div>
<h4 class="mb-3">Order This Plan</h4>
{% load contact_tags %}
{% embedded_contact_form source="Plan Order" service=offering.service offering_id=offering.id plan_id=plan.id %}
</div>
</div>
</div>
{% empty %}
@ -167,6 +162,18 @@
</div>
{% endfor %}
</div>
{% if offering.plans.exists %}
<div class="pt-40">
<h4 class="fs-22 fw-semibold lh-1 mb-12">I'm interested in a plan</h4>
<div class="row">
<div class="col-12">
{% load contact_tags %}
{% embedded_contact_form source="Plan Order" service=offering.service offering_id=offering.id choices=offering.plans.all choice_label="Select a Plan" %}
</div>
</div>
</div>
{% endif %}
</div>
</div>
</div>

View file

@ -8,7 +8,14 @@ register = template.Library()
@register.inclusion_tag("services/embedded_contact_form.html", takes_context=True)
def embedded_contact_form(
context, source=None, details=None, service=None, offering_id=None, plan_id=None
context,
source=None,
details=None,
service=None,
offering_id=None,
plan_id=None,
choices=None,
choice_label=None,
):
"""
Renders an embedded contact form with optional service context information.
@ -17,6 +24,7 @@ def embedded_contact_form(
{% load contact_tags %}
{% embedded_contact_form source="Partner Page" details="ACME Corp" %}
{% embedded_contact_form service=service offering_id=offering.id plan_id=plan.id %}
{% embedded_contact_form service=service offering_id=offering.id choices=offering.plans.all choice_label="Select a Plan" %}
"""
request = context["request"]
form = LeadForm()
@ -25,6 +33,11 @@ def embedded_contact_form(
offering_obj = None
plan_obj = None
# Process choices if they're QuerySet objects (like plans)
processed_choices = None
if choices:
processed_choices = [(str(choice.id), choice.name) for choice in choices]
# Resolve service/offering/plan objects if IDs provided
if service and isinstance(service, str):
try:
@ -56,4 +69,6 @@ def embedded_contact_form(
"offering": offering_obj,
"plan": plan_obj,
"request": request,
"choices": processed_choices,
"choice_label": choice_label,
}

View file

@ -26,7 +26,7 @@ def contact_form(request):
lead = Lead(
name=form.cleaned_data["name"],
email=form.cleaned_data["email"],
message=form.cleaned_data["message"],
message=form.cleaned_data["message"] or "",
company=form.cleaned_data["company"],
phone=form.cleaned_data["phone"],
)
@ -87,6 +87,22 @@ def contact_form(request):
if plan_name:
service_info.append(f"Plan: {plan_name}")
# Handle selected choice if present
selected_choice = request.POST.get("selected_choice", "")
if selected_choice:
try:
choice_id, choice_name = selected_choice.split("|", 1)
# Add selected choice to message
service_info.append(f"Selected Plan: {choice_name}")
# Try to set the plan based on the choice_id
try:
lead.plan = Plan.objects.get(id=choice_id)
except Plan.DoesNotExist:
pass
except ValueError:
pass
if service_info:
context_info.append("Service Information: " + ", ".join(service_info))