Skip to content

Commit 9f9abce

Browse files
committed
Preserve field values on unsuccessful form submission
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
1 parent 848a00e commit 9f9abce

File tree

2 files changed

+17
-42
lines changed

2 files changed

+17
-42
lines changed

vulnerabilities/forms.py

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,7 @@ class AdvisorySearchForm(forms.Form):
4646
class ApiUserCreationForm(forms.ModelForm):
4747
"""Support a simplified creation for API-only users directly from the UI."""
4848

49-
captcha = AltchaField(
50-
floating=True,
51-
hidefooter=True,
52-
hidelogo=True,
53-
)
49+
captcha = AltchaField(floating=True, hidefooter=True)
5450

5551
class Meta:
5652
model = ApiUser
@@ -66,18 +62,15 @@ def __init__(self, *args, **kwargs):
6662
first_name_field = self.fields["first_name"]
6763
last_name_field = self.fields["last_name"]
6864
email_field.required = True
69-
email_field.label = "Email"
7065
email_field.widget.attrs["class"] = "input"
71-
email_field.widget.attrs["style"] = "width: 50%"
72-
email_field.widget.attrs["placeholder"] = "foo@bar.com"
73-
first_name_field.label = "First Name"
66+
email_field.widget.attrs["placeholder"] = "Email"
7467
first_name_field.widget.attrs["class"] = "input"
75-
first_name_field.widget.attrs["style"] = "width: 50%"
76-
first_name_field.widget.attrs["placeholder"] = "Jon"
77-
last_name_field.label = "Last Name"
68+
first_name_field.widget.attrs["placeholder"] = "First Name"
7869
last_name_field.widget.attrs["class"] = "input"
79-
last_name_field.widget.attrs["style"] = "width: 50%"
80-
last_name_field.widget.attrs["placeholder"] = "Doe"
70+
last_name_field.widget.attrs["placeholder"] = "Last Name"
71+
email_field.label = ""
72+
first_name_field.label = ""
73+
last_name_field.label = ""
8174

8275
def save(self, commit=True):
8376
return ApiUser.objects.create_api_user(
@@ -109,8 +102,4 @@ class PipelineSchedulePackageForm(forms.Form):
109102

110103

111104
class AdminLoginForm(AdminAuthenticationForm):
112-
captcha = AltchaField(
113-
floating=True,
114-
hidefooter=True,
115-
hidelogo=True,
116-
)
105+
captcha = AltchaField(floating=True, hidefooter=True)

vulnerabilities/templates/api_user_creation_form.html

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
VulnerableCode API key request
55
{% endblock %}
66

7+
8+
79
{% block content %}
810
<section class="section pt-0">
911
{% for message in messages %}
@@ -44,31 +46,15 @@ <h1 class="title is-4">VulnerableCode API Key Request</h1>
4446

4547
<br/>
4648
<div class="columns is-centered">
47-
<div class="column is-half">
49+
<div class="column is-one-third">
4850
<form method = "post">
4951
{% csrf_token %}
50-
<div class="field">
51-
<div class="control">
52-
<input class="input" placeholder="Email" type="email" name="email" id="{{form.email.id_for_label}}"
53-
autofocus required >
54-
</div>
55-
</div>
56-
<div class="field">
57-
<div class="control">
58-
<input class="input" placeholder="First Name" type="text" name="first_name" id="{{form.first_name.id_for_label}}"
59-
autofocus required>
60-
</div>
61-
</div>
62-
<div class="field">
63-
<div class="control">
64-
<input class="input" placeholder="Last Name" type="text" name="last_name" id="{{form.last_name.id_for_label}}"
65-
autofocus required>
66-
</div>
67-
</div>
68-
<div class="field">
69-
{{ form.captcha }}
70-
</div>
71-
<input class="button is-link mt-5" type="submit" value="Request my API Key">
52+
{% for field in form %}
53+
<p class="mb-4">
54+
{{ field }}
55+
</p>
56+
{% endfor %}
57+
<input class="button is-link mt-2" type="submit" value="Request my API Key">
7258
</form>
7359
</div>
7460
</div>

0 commit comments

Comments
 (0)