Add form instructions and make email optional

- Display brief instructions above the guestbook form.
- Update validation: require first name, last name, and location; make email optional.
- Remove the 'required' attribute from the email input field.
- Provide context in the UI so users understand why email is optional.
This commit is contained in:
Steve Dogiakos 2025-04-01 18:38:39 -06:00
parent 4623e014a5
commit 9ce656a963
2 changed files with 14 additions and 9 deletions

12
app.py
View File

@ -18,7 +18,7 @@ def init_db():
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
first_name TEXT NOT NULL, first_name TEXT NOT NULL,
last_name TEXT NOT NULL, last_name TEXT NOT NULL,
email TEXT NOT NULL, email TEXT,
location TEXT NOT NULL, location TEXT NOT NULL,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
) )
@ -42,11 +42,11 @@ def index():
email = request.form.get('email', '').strip() email = request.form.get('email', '').strip()
location = request.form.get('location', '').strip() location = request.form.get('location', '').strip()
# Basic validation checks # Basic validation checks (email is optional)
if not (first_name and last_name and email and location): if not (first_name and last_name and location):
error = "All fields are required." error = "First name, last name, and location are required."
logger.warning("Validation error: Missing required fields.") logger.warning("Validation error: Missing required fields (first name, last name, location).")
elif not is_valid_email(email): elif email and not is_valid_email(email):
error = "Invalid email address." error = "Invalid email address."
logger.warning("Validation error: Invalid email address '%s'.", email) logger.warning("Validation error: Invalid email address '%s'.", email)

View File

@ -22,7 +22,6 @@
.scrolling-content { .scrolling-content {
display: inline-block; display: inline-block;
padding: 10px; padding: 10px;
/* Adjust the animation duration to control speed */
animation: scroll-left 20s linear infinite; animation: scroll-left 20s linear infinite;
} }
@ -42,6 +41,12 @@
<div class="container mt-5 mb-5"> <div class="container mt-5 mb-5">
<h1 class="mb-4">Museum Visitor Guestbook</h1> <h1 class="mb-4">Museum Visitor Guestbook</h1>
<!-- Brief instructions for the form -->
<div class="alert alert-info" role="alert">
Please fill in your details below. First name, last name, and location are required.
Providing your email is optional, but it helps us follow up if needed.
</div>
{% if error %} {% if error %}
<div class="alert alert-danger" role="alert"> <div class="alert alert-danger" role="alert">
{{ error }} {{ error }}
@ -58,8 +63,8 @@
<input type="text" class="form-control" id="last_name" name="last_name" required> <input type="text" class="form-control" id="last_name" name="last_name" required>
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label for="email" class="form-label">Email:</label> <label for="email" class="form-label">Email (Optional):</label>
<input type="email" class="form-control" id="email" name="email" required> <input type="email" class="form-control" id="email" name="email">
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label for="location" class="form-label">Location:</label> <label for="location" class="form-label">Location:</label>