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.
|
||||
"""
|
||||
if request.method == 'POST':
|
||||
email = request.form.get('email', '').strip().lower()
|
||||
if not is_valid_email(email):
|
||||
form_data = {
|
||||
'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')
|
||||
return render_template('request.html'), 400
|
||||
rid = create_request(
|
||||
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(),
|
||||
)
|
||||
return render_template('request.html', form=form_data), 400
|
||||
rid = create_request(**form_data)
|
||||
|
||||
# Send confirmation email with a summary of what the customer asked for.
|
||||
req = get_request_by_id(rid)
|
||||
|
|
@ -365,7 +365,7 @@ def request_form():
|
|||
|
||||
flash('Your request has been submitted! Check your email soon.', 'success')
|
||||
return redirect(url_for('thanks', rid=rid))
|
||||
return render_template('request.html')
|
||||
return render_template('request.html', form=None)
|
||||
|
||||
|
||||
@app.route('/thanks/<int:rid>')
|
||||
|
|
|
|||
Reference in a new issue