Beispiel #1
0
def form(request):
    form = forms.ContactForm()
    if request.method == 'POST':
        form_data = forms.ContactForm(request.POST)
        if form_data.is_valid():
            name = form_data.cleaned_data.get('name')
            num = form_data.cleaned_data.get('num')
            phone = form_data.cleaned_data.get('phone')
            d = {'name': name, 'num': num, 'phone': phone}
            return render(request, 'form_data.html', context=d)

    return render(request, 'form.html', context={'form': form})
Beispiel #2
0
def contact_page():
    form = forms.ContactForm()

    if request.method == 'POST':
        if not form.validate():
            flash('All fields are required.')
            return render_template('contact.html',
                                   config=_get_template_config(),
                                   form=form)
        else:

            name = form.name.data
            email = form.email.data
            message = form.message.data
            user = g.user if g.user.is_authenticated else None

            controllers.ContactController.create_contact(message,
                                                         email=email,
                                                         name=name,
                                                         user=user)
            flash('Thank you for the feedback!')

            return redirect('/index')

    elif request.method == 'GET':
        return render_template('contact.html',
                               config=_get_template_config(),
                               form=form)
Beispiel #3
0
def validate(request):
    form = forms.ContactForm()
    if request.method == 'POST':
        form_data = forms.ContactForm(request.POST)
        if form_data.is_valid():
            name = form_data.cleaned_data.get('name')
            number = form_data.cleaned_data.get('number')
            Email = form_data.cleaned_data.get('Email')
            Re_Enter_Email = form_data.cleaned_data.get('Re_Enter_Email')
            d = {
                'name': name,
                'number': number,
                'Email': Email,
                'Re_Enter_Email': Re_Enter_Email
            }
            return render(request, 'form_data.html', context=d)

    return render(request, 'form.html', context={'form': form})
Beispiel #4
0
def contact_view():
    form = forms.ContactForm()
    if form.validate_on_submit():
        message = Message(name=form.name.data,
                          email=form.email.data,
                          message=form.message.data)
        db.session.add(message)
        db.session.commit()
        return redirect('/')
    return render_template('contact_me.html', title='contact me', form=form)
Beispiel #5
0
def contact():
    form = forms.ContactForm()
    if form.validate_on_submit():
        msg = Message(request.form['subject'],
                      sender=(request.form['name'], request.form['email']),
                      recipients=["*****@*****.**"])
        msg.body = 'This is the body of the message'
        mail.send(msg)
        flash('You successfully sent your message.')
        return redirect(url_for('home'))
    return render_template('contact.html', form=form)
Beispiel #6
0
def contact():
    form = forms.ContactForm()
    if form.validate_on_submit():
        msg = Message(form.subject.data,
                      sender=(form.name.data, form.email.data),
                      recipients=["*****@*****.**"])
        msg.body = form.message.data
        mail.send(msg)
        flash("Your message has been sent successfully")
        return redirect(url_for('home'))
    return render_template('contact.html', form=form)
Beispiel #7
0
def contact():
    render_template('contact.html')
    form = forms.ContactForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            msg = Message(form.subject.data,
                          sender=(form.name.data, form.email.data),
                          recipients=[smtp.mailtrap.io])
            msg.body = 'This is the body of the message'
            mail.send(msg)
            return redirect(url_for('home'))
            flash('you successfully submitted the contact form.')
Beispiel #8
0
def contact():
    form = forms.ContactForm()
    if request.method == 'POST' and form.validate_on_submit():
        msg = Message(form.subject.data,
                      sender=(form.firstname.data + " " + form.lastname.data,
                              form.email.data),
                      recipients=["*****@*****.**"])
        msg.body = form.message.data
        mail.send(msg)
        flash('You have successfully filled out the form', 'success')
        return redirect(url_for('home'))
    return render_template('contact.html', form=form)
Beispiel #9
0
def add_customer():
    form = forms.ContactForm()
    if form.validate_on_submit():
        if models.Customer.try_add(name=form.name.data,
                                   contact=form.contact.data,
                                   address=form.address.data):
            flash('Successfully added new customer')
        else:
            flash('Fail to add new customer to database.\nError: {}' \
                  .format(models.Customer.error))

        return redirect(url_for('add_customer'))

    return render_template('add/add-customer.html', form=form)
Beispiel #10
0
def contact():
    form = forms.ContactForm()
    if form.validate_on_submit() and request.method == 'POST':
        msg = Message(form.subject.data,
                      sender=(form.name.data, form.email.data),
                      recipients=["*****@*****.**"])
        msg.body = form.message.data
        mail.send(msg)
        flash('Your message has been sent!')
        return redirect(url_for('home.html', mailed=True))

    elif request.method == 'POST':
        return render_template('contact.html', form=form, invalid=True)
    return render_template('contact.html', form=form, invalid=False)
Beispiel #11
0
def edit_customer(id=None):
    if not id:
        return redirect(url_for(customers.__name__))

    customer = models.Customer.get(id)
    if not customer:
        return redirect(url_for(customers.__name__))

    form = forms.ContactForm(obj=customer)

    if request.method == 'POST':
        if form.validate_on_submit():
            customer.name = form.name.data
            customer.contact = form.contact.data
            customer.address = form.address.data
            models.ItemType.update(customer)
            flash_format('Successfully edited {}', customer.name)
            return redirect(url_for(customers.__name__))

    return render_template('edit/edit-customer.html', form=form)
Beispiel #12
0
def contact():
    """Render the website's contact page."""
    form = forms.ContactForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            # Note the difference when retrieving form data using Flask-WTF
            # Here we use myform.firstname.data instead of request.form['firstname']
            name = form.name.data
            email = form.email.data
            subject = form.subject.data
            message = form.message.data

            flash('You have successfully filled out the form', 'success')
            msg = Message(subject,
                          sender='*****@*****.**',
                          recipients=[email])
            msg.body = message
            mail.send(msg)
            return redirect('/')
        flash_errors(form)
    return render_template('contact.html', form=form)