From 9ce656a96357ba51eefe00b947130df33c8a1bdc Mon Sep 17 00:00:00 2001 From: Steve Dogiakos Date: Tue, 1 Apr 2025 18:38:39 -0600 Subject: [PATCH] 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. --- app.py | 12 ++++++------ templates/index.html | 11 ++++++++--- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app.py b/app.py index 96393ee..94429a3 100644 --- a/app.py +++ b/app.py @@ -18,7 +18,7 @@ def init_db(): id INTEGER PRIMARY KEY AUTOINCREMENT, first_name TEXT NOT NULL, last_name TEXT NOT NULL, - email TEXT NOT NULL, + email TEXT, location TEXT NOT NULL, timestamp DATETIME DEFAULT CURRENT_TIMESTAMP ) @@ -42,11 +42,11 @@ def index(): email = request.form.get('email', '').strip() location = request.form.get('location', '').strip() - # Basic validation checks - if not (first_name and last_name and email and location): - error = "All fields are required." - logger.warning("Validation error: Missing required fields.") - elif not is_valid_email(email): + # Basic validation checks (email is optional) + if not (first_name and last_name and location): + error = "First name, last name, and location are required." + logger.warning("Validation error: Missing required fields (first name, last name, location).") + elif email and not is_valid_email(email): error = "Invalid email address." logger.warning("Validation error: Invalid email address '%s'.", email) diff --git a/templates/index.html b/templates/index.html index 6c10d9d..4abf49c 100644 --- a/templates/index.html +++ b/templates/index.html @@ -22,7 +22,6 @@ .scrolling-content { display: inline-block; padding: 10px; - /* Adjust the animation duration to control speed */ animation: scroll-left 20s linear infinite; } @@ -42,6 +41,12 @@

Museum Visitor Guestbook

+ + + {% if error %}
- - + +