fix: keep form values and show email error on request page
This commit is contained in:
parent
bf9f9e09fd
commit
382b05d7f8
2 changed files with 59 additions and 44 deletions
26
app.py
26
app.py
|
|
@ -323,19 +323,19 @@ def request_form():
|
||||||
Rate limited to 5 submissions per minute per IP.
|
Rate limited to 5 submissions per minute per IP.
|
||||||
"""
|
"""
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
email = request.form.get('email', '').strip().lower()
|
form_data = {
|
||||||
if not is_valid_email(email):
|
'name': request.form.get('name', '').strip(),
|
||||||
|
'email': request.form.get('email', '').strip().lower(),
|
||||||
|
'hobbies': request.form.get('hobbies', '').strip(),
|
||||||
|
'notable_facts': request.form.get('notable_facts', '').strip(),
|
||||||
|
'style_genre': request.form.get('style_genre', '').strip(),
|
||||||
|
'extra_requests': request.form.get('extra_requests', '').strip(),
|
||||||
|
'vocal_gender': request.form.get('vocal_gender', '').strip(),
|
||||||
|
}
|
||||||
|
if not is_valid_email(form_data['email']):
|
||||||
flash('Please enter a valid email address.', 'error')
|
flash('Please enter a valid email address.', 'error')
|
||||||
return render_template('request.html'), 400
|
return render_template('request.html', form=form_data), 400
|
||||||
rid = create_request(
|
rid = create_request(**form_data)
|
||||||
name=request.form.get('name', '').strip(),
|
|
||||||
email=email,
|
|
||||||
hobbies=request.form.get('hobbies', '').strip(),
|
|
||||||
notable_facts=request.form.get('notable_facts', '').strip(),
|
|
||||||
style_genre=request.form.get('style_genre', '').strip(),
|
|
||||||
extra_requests=request.form.get('extra_requests', '').strip(),
|
|
||||||
vocal_gender=request.form.get('vocal_gender', '').strip(),
|
|
||||||
)
|
|
||||||
|
|
||||||
# Send confirmation email with a summary of what the customer asked for.
|
# Send confirmation email with a summary of what the customer asked for.
|
||||||
req = get_request_by_id(rid)
|
req = get_request_by_id(rid)
|
||||||
|
|
@ -365,7 +365,7 @@ def request_form():
|
||||||
|
|
||||||
flash('Your request has been submitted! Check your email soon.', 'success')
|
flash('Your request has been submitted! Check your email soon.', 'success')
|
||||||
return redirect(url_for('thanks', rid=rid))
|
return redirect(url_for('thanks', rid=rid))
|
||||||
return render_template('request.html')
|
return render_template('request.html', form=None)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/thanks/<int:rid>')
|
@app.route('/thanks/<int:rid>')
|
||||||
|
|
|
||||||
|
|
@ -105,50 +105,65 @@
|
||||||
font-size:1.3rem;
|
font-size:1.3rem;
|
||||||
vertical-align:middle;
|
vertical-align:middle;
|
||||||
}
|
}
|
||||||
|
.flash{
|
||||||
|
padding:.8rem;
|
||||||
|
background:#064e3b;
|
||||||
|
border-radius:.5rem;
|
||||||
|
margin-bottom:1rem;
|
||||||
|
}
|
||||||
|
.flash.error{background:#450a0a;}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<!-- Banner graphic for the booth. Served from /static. -->
|
<!-- Banner graphic for the booth. Served from /static. -->
|
||||||
<img src="{{ url_for('static', filename='Trollgorithm_booth.jpg') }}" alt="Trollgorithm Theme Song Booth" class="banner">
|
<img src="{{ url_for('static', filename='Trollgorithm_booth.jpg') }}" alt="Trollgorithm Theme Song Booth" class="banner">
|
||||||
|
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<h1><span class="sparkle">🎵</span> Get Your Custom Theme Song <span class="sparkle">🎶</span></h1>
|
<h1><span class="sparkle">🎵</span> Get Your Custom Theme Song <span class="sparkle">🎶</span></h1>
|
||||||
<p class="subtitle">Tell us about yourself and we'll craft a one-of-a-kind song just for you.</p>
|
<p class="subtitle">Tell us about yourself and we'll craft a one-of-a-kind song just for you.</p>
|
||||||
|
|
||||||
<form method="POST">
|
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||||
<label for="name">Name / persona you want in the song</label>
|
{% if messages %}
|
||||||
<input type="text" id="name" name="name" required>
|
{% for category, message in messages %}
|
||||||
|
<div class="flash {{ category }}">{{ message }}</div>
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
{% endwith %}
|
||||||
|
|
||||||
<label for="email">Email address</label>
|
<form method="POST">
|
||||||
<input type="email" id="email" name="email" required>
|
<label for="name">Name / persona you want in the song</label>
|
||||||
|
<input type="text" id="name" name="name" value="{{ form.name if form else '' }}" required>
|
||||||
|
|
||||||
<label for="hobbies">Hobbies & interests</label>
|
<label for="email">Email address</label>
|
||||||
<textarea id="hobbies" name="hobbies" placeholder="e.g. rock climbing, retro gaming, sourdough baking"></textarea>
|
<input type="email" id="email" name="email" value="{{ form.email if form else '' }}" required>
|
||||||
|
|
||||||
<label for="notable_facts">Notable things about you</label>
|
<label for="hobbies">Hobbies & interests</label>
|
||||||
<textarea id="notable_facts" name="notable_facts" placeholder="Anything fun, weird, or heroic we should mention"></textarea>
|
<textarea id="hobbies" name="hobbies" placeholder="e.g. rock climbing, retro gaming, sourdough baking">{{ form.hobbies if form else '' }}</textarea>
|
||||||
|
|
||||||
<label for="style_genre">Style / genre / mood</label>
|
<label for="notable_facts">Notable things about you</label>
|
||||||
<input type="text" id="style_genre" name="style_genre" placeholder="e.g. 80s power ballad, cinematic orchestral, lo-fi synthwave">
|
<textarea id="notable_facts" name="notable_facts" placeholder="Anything fun, weird, or heroic we should mention">{{ form.notable_facts if form else '' }}</textarea>
|
||||||
|
|
||||||
<label for="vocal_gender">Preferred singer voice / gender</label>
|
<label for="style_genre">Style / genre / mood</label>
|
||||||
<select id="vocal_gender" name="vocal_gender">
|
<input type="text" id="style_genre" name="style_genre" value="{{ form.style_genre if form else '' }}" placeholder="e.g. 80s power ballad, cinematic orchestral, lo-fi synthwave">
|
||||||
<option value="" selected>No preference</option>
|
|
||||||
<option value="female">Female</option>
|
|
||||||
<option value="male">Male</option>
|
|
||||||
<option value="non-binary">Non-binary / Gender-neutral</option>
|
|
||||||
<option value="androgynous">Androgynous</option>
|
|
||||||
<option value="other">Other (mention in Extra Requests)</option>
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<label for="extra_requests">Anything else you want in the song?</label>
|
<label for="vocal_gender">Preferred singer voice / gender</label>
|
||||||
<textarea id="extra_requests" name="extra_requests" placeholder="Specific lyrics, vibe, clean/explicit, vocal gender..."></textarea>
|
<select id="vocal_gender" name="vocal_gender">
|
||||||
|
<option value="" {% if not form or not form.vocal_gender %}selected{% endif %}>No preference</option>
|
||||||
|
<option value="female" {% if form and form.vocal_gender == 'female' %}selected{% endif %}>Female</option>
|
||||||
|
<option value="male" {% if form and form.vocal_gender == 'male' %}selected{% endif %}>Male</option>
|
||||||
|
<option value="non-binary" {% if form and form.vocal_gender == 'non-binary' %}selected{% endif %}>Non-binary / Gender-neutral</option>
|
||||||
|
<option value="androgynous" {% if form and form.vocal_gender == 'androgynous' %}selected{% endif %}>Androgynous</option>
|
||||||
|
<option value="other" {% if form and form.vocal_gender == 'other' %}selected{% endif %}>Other (mention in Extra Requests)</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
<button type="submit">Submit Request</button>
|
<label for="extra_requests">Anything else you want in the song?</label>
|
||||||
</form>
|
<textarea id="extra_requests" name="extra_requests" placeholder="Specific lyrics, vibe, clean/explicit, vocal gender...">{{ form.extra_requests if form else '' }}</textarea>
|
||||||
<p class="note">Your info is only used to create and deliver your song.</p>
|
|
||||||
</div>
|
<button type="submit">Submit Request</button>
|
||||||
|
</form>
|
||||||
|
<p class="note">Your info is only used to create and deliver your song.</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
Reference in a new issue