from flask_mail import Mail, Message
app.config['MAIL_SERVER'] = 'xxxx'
app.config['MAIL_PORT'] = 465
app.config['MAIL_USERNAME'] = 'xxxx'
app.config['MAIL_PASSWORD'] = 'xxxx'
app.config['MAIL_USE_TLS'] = False
app.config['MAIL_USE_SSL'] = True
app.config['MAIL_DEFAULT_SENDER'] = 'xxx'
mail = Mail(app)
app.config['SECRET_KEY'] = 'xxx'
# Contact Form
class ContactForm(FlaskForm):
name =StringField("Name",validators=[DataRequired()])
email = StringField("Email",validators=[DataRequired(), Email()])
message = TextAreaField("Message",validators=[DataRequired()])
submit = SubmitField('Send')
@app.route('/', methods=['GET', 'POST'])
def home():
form = ContactForm()
if form.validate_on_submit() == False:
return render_template('home2.html',form=form)
else:
msg = Message('WEBSITE CONTACT', sender='xxx', recipients=['xxxx'])
msg.body = '%s \n %s \n\n %s ' % (form.name.data, form.email.data, form.message.data)
mail.send(msg)
return redirect(url_for('form_complete'))
return render_template('home2.html',form=form)
@app.route('/complete')
def form_complete():
return render_template('form_submitted.html')
The contact form successfully sends the email, however it does not redirect to form_complete.
I would like, after the contact form has been submitted (via a bootstrap button), for an email to be sent and a redirect to form_submitted.html
Furthermore, if I change the class in the HTML, the Send text just disappears:
...
<div class="container">
<h3 class="big text-center" data-aos="fade-down" data-aos-delay="0">
Contact
</h3>
<form method="POST" action ="">
<!--{# #}-->
</form>
</div>
...
edit: When the submit button is pressed the contact form correctly sends to my email, though it doesn't redirect as I would like.
There is a script.js containing some remnant php form info - but removing this from script.js has not changed anything.
Github: https://github.com/olbliss/OB_Flask
from Flask - contact form sending email on submit, but not redirecting and bootstrap btn not showing

No comments:
Post a Comment