Untitled

mail@pastecode.io avatar
unknown
python
11 days ago
3.1 kB
5
Indexable
Never
---------inquiry.html


<!-- templates/inquiry.html -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Inquiry Form</title>
    <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/styles.css') }}">
</head>
<body>
    <header>
        <h1>Submit Your Inquiry</h1>
        <nav>
            <a href="/">Home</a> |
            <a href="/about">About</a>
        </nav>
    </header>
    <main>
        <form method="POST" action="/inquiry">
            <label for="name">Name:</label>
            <input type="text" id="name" name="name" required><br><br>

            <label for="email">Email:</label>
            <input type="email" id="email" name="email" required><br><br>

<!--             <label for="phone">Phone:</label>-->
<!--            <input type="phone" id="phone" name="phone" required><br><br>-->

            <label for="message">Message:</label>
            <textarea id="message" name="message" rows="5" required></textarea><br><br>

            <input type="submit" value="Submit">
        </form>
    </main>
</body>
</html>





-----------app.py

from flask import Flask, render_template, request, redirect, url_for
from flask_sqlalchemy import SQLAlchemy
import os

app = Flask(__name__)


@app.route('/')
def home():
    return render_template('index.html')

@app.route('/about')
def about():
    return render_template('about.html')

@app.route('/inventory')
def inventory():
    return render_template('inventory.html')

@app.route('/contact')
def contact():
    return render_template('contact.html')

basedir = os.path.abspath(os.path.dirname(__file__))
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'gwc_inquiries.db')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

db = SQLAlchemy(app)

# define model/table schema)
class Inquiry(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(100), nullable=False)
    email = db.Column(db.String(120), nullable=False)
    message = db.Column(db.Text, nullable=False)

    def __init__(self, name, email, message):
        self.name = name
        self.email = email
        self.message = message



# Route for the inquiry form
@app.route('/inquiry', methods=['GET', 'POST'])
def inquiry():
    if request.method == 'POST':
        name = request.form['name']
        email = request.form['email']
        # phone = request.form['phone']
        message = request.form['message']

        # Create a new inquiry instance
        new_inquiry = Inquiry(name=name, email=email, message=message)

        # Add and commit to the database
        db.session.add(new_inquiry)
        db.session.commit()

        return redirect(url_for('thank_you'))
    return render_template('inquiry.html')


@app.route('/thank-you')
def thank_you():
    return '<h1>Thank you for your inquiry!</h1>'

with app.app_context():
    db.create_all()



if __name__ == '__main__':
    app.run(debug=True)
Leave a Comment