Update app.py
This commit is contained in:
10
app.py
10
app.py
@ -195,11 +195,13 @@ def submit_contact():
|
||||
try:
|
||||
# Get form data
|
||||
data = request.get_json()
|
||||
print('DEBUG: Received form data:', data)
|
||||
|
||||
# Validate required fields
|
||||
required_fields = ['firstName', 'lastName', 'email', 'service', 'message']
|
||||
for field in required_fields:
|
||||
if not data.get(field) or not data[field].strip():
|
||||
print(f'DEBUG: Missing required field: {field}')
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'message': f'{field.replace("firstName", "First name").replace("lastName", "Last name").title()} is required'
|
||||
@ -207,6 +209,7 @@ def submit_contact():
|
||||
|
||||
# Validate email format
|
||||
if not validate_email(data['email']):
|
||||
print('DEBUG: Invalid email format:', data['email'])
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'message': 'Please enter a valid email address'
|
||||
@ -214,6 +217,7 @@ def submit_contact():
|
||||
|
||||
# Validate phone if provided
|
||||
if data.get('phone') and not validate_phone(data['phone']):
|
||||
print('DEBUG: Invalid phone format:', data['phone'])
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'message': 'Please enter a valid phone number'
|
||||
@ -230,9 +234,11 @@ def submit_contact():
|
||||
'budget': data.get('budget', '').strip(),
|
||||
'message': data['message'].strip()
|
||||
}
|
||||
print('DEBUG: Prepared form data for email:', form_data)
|
||||
|
||||
# Send email
|
||||
success, message = send_contact_email(form_data)
|
||||
print('DEBUG: Email send result:', success, message)
|
||||
|
||||
if success:
|
||||
return jsonify({
|
||||
@ -240,12 +246,16 @@ def submit_contact():
|
||||
'message': 'Thank you for your message! I will get back to you within 48 hours.'
|
||||
})
|
||||
else:
|
||||
print('DEBUG: Email sending failed:', message)
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'message': 'Sorry, there was an error sending your message. Please try again or contact me directly.'
|
||||
}), 500
|
||||
|
||||
except Exception as e:
|
||||
import traceback
|
||||
print('DEBUG: Exception in /contact POST route:', e)
|
||||
traceback.print_exc()
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'message': 'An unexpected error occurred. Please try again.'
|
||||
|
||||
Reference in New Issue
Block a user