Repository: cal-itp/benefits

Issue:
Update eligibility verification form to use dynamic data
## Background

This builds on #208 and #319 to incorporate specific `EligibilityVerifier` properties into the [eligibility verification form](https://github.com/cal-itp/benefits/blob/dev/benefits/eligibility/forms.py#L15)

## Tasks

* [x] Create an `__init__()` method on the form class accepting a new kwarg `verifier` of type `EligibilityVerifier`
* [x] If the `verifier.form_sub_pattern` field has a value, add a `pattern` attribute with the value to the `sub` input via [Widget.attrs](https://docs.djangoproject.com/en/3.2/ref/forms/widgets/#django.forms.Widget.attrs)
* [x] If the `verifier.form_name_max_length` field has a value, add a `maxlength` attribute to the `name` input via Widgets.attrs
* [x] Use attributes from the `verifier` as `msgid` keys for labels etc.
* [x] Rework the [`eligibility:confirm` view](https://github.com/cal-itp/benefits/blob/dev/benefits/eligibility/views.py#L46) to initialize the `Page` viewmodel and eligibility verification form from the selected verifier


Discussion:
RE: the final task to use the new form text properties from #319 -- we have to be careful of when to use the **lazy** versions of Django's helper functions for text translations.

E.g. in [`benefits/eligibility/forms.py`](https://github.com/cal-itp/benefits/blob/dev/benefits/eligibility/forms.py#L7):

```python
from django.utils.translation import gettext_lazy as _
```

Different from e.g. [`benefits/eligibility/views.py`](https://github.com/cal-itp/benefits/blob/dev/benefits/eligibility/views.py#L8):

```python
from django.utils.translation import gettext as _
```

Read more about [lazy translation in Django](https://docs.djangoproject.com/en/3.2/topics/i18n/translation/#lazy-translation)

Resolving patch:
diff --git a/benefits/eligibility/forms.py b/benefits/eligibility/forms.py
--- a/benefits/eligibility/forms.py
+++ b/benefits/eligibility/forms.py
@@ -6,7 +6,7 @@
 from django import forms
 from django.utils.translation import gettext_lazy as _
 
-from benefits.core import recaptcha, widgets
+from benefits.core import models, recaptcha, widgets
 
 
 logger = logging.getLogger(__name__)
@@ -18,14 +18,6 @@ class EligibilityVerificationForm(forms.Form):
     action_url = "eligibility:confirm"
     method = "POST"
 
-    sub = forms.CharField(
-        label=_("eligibility.forms.confirm.fields.sub"), widget=widgets.FormControlTextInput(placeholder="A1234567")
-    )
-
-    name = forms.CharField(
-        label=_("eligibility.forms.confirm.fields.name"), widget=widgets.FormControlTextInput(placeholder="Rodriguez")
-    )
-
     submit_value = _("eligibility.forms.confirm.submit")
     submitting_value = _("eligibility.forms.confirm.submitting")
 
@@ -34,6 +26,21 @@ class EligibilityVerificationForm(forms.Form):
         "missing": _("eligibility.forms.confirm.errors.missing"),
     }
 
+    def __init__(self, verifier: models.EligibilityVerifier, *args, **kwargs):
+        super().__init__(*args, **kwargs)
+
+        sub_widget = widgets.FormControlTextInput(placeholder=verifier.form_sub_placeholder)
+        if verifier.form_sub_pattern:
+            sub_widget.attrs.update({"pattern": verifier.form_sub_pattern})
+
+        self.fields["sub"] = forms.CharField(label=_(verifier.form_sub_label), widget=sub_widget)
+
+        name_widget = widgets.FormControlTextInput(placeholder=verifier.form_name_placeholder)
+        if verifier.form_name_max_length:
+            name_widget.attrs.update({"maxlength": verifier.form_name_max_length})
+
+        self.fields["name"] = forms.CharField(label=_(verifier.form_name_label), widget=name_widget)
+
     def add_api_errors(self, form_errors):
         """Handle errors passed back from API server related to submitted form values."""
 
diff --git a/benefits/eligibility/views.py b/benefits/eligibility/views.py
--- a/benefits/eligibility/views.py
+++ b/benefits/eligibility/views.py
@@ -48,18 +48,20 @@ def index(request):
 def confirm(request):
     """View handler for the eligibility verification form."""
 
+    verifier = session.verifier(request)
+
     page = viewmodels.Page(
-        title=_("eligibility.pages.confirm.title"),
-        content_title=_("eligibility.pages.confirm.content_title"),
-        paragraphs=[_("eligibility.pages.confirm.p[0]")],
-        form=forms.EligibilityVerificationForm(auto_id=True, label_suffix=""),
+        title=_(verifier.form_title),
+        content_title=_(verifier.form_content_title),
+        paragraphs=[_(verifier.form_blurb)],
+        form=forms.EligibilityVerificationForm(auto_id=True, label_suffix="", verifier=verifier),
         classes="text-lg-center",
     )
 
     if request.method == "POST":
         analytics.started_eligibility(request)
 
-        form = forms.EligibilityVerificationForm(request.POST)
+        form = forms.EligibilityVerificationForm(data=request.POST, verifier=verifier)
         response = _verify(request, form)
 
         if response is None:


Test patch: