Skip to content

monesh-sys/Mini-Form

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

from flask import Flask, request, render_template_string, send_file import csv import qrcode from pyngrok import ngrok

app = Flask(name)

--- NGROK SETUP ---

port = 5000 # Flask port public_url = ngrok.connect(port) print("Ngrok URL:", public_url) # Share this URL to access from anywhere

--- QR CODE FOR MOBILE ---

img = qrcode.make(public_url) # QR points to Ngrok public URL img.save("flask_qr.png") # Saved in same folder

--- ANIMATED CSS ---

animated_bg = """

<style> body { margin: 0; height: 100vh; display: flex; justify-content: center; align-items: center; font-family: Arial; color: white; background: linear-gradient(-45deg, #000000, #111111, #222222, #000000); background-size: 400% 400%; animation: gradientBG 10s ease infinite; } @keyframes gradientBG { 0% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } 100% { background-position: 0% 50%; } } .container { background: rgba(0, 0, 0, 0.55); padding: 30px; width: 85%; max-width: 400px; border-radius: 15px; box-shadow: 0 0 20px rgba(255,255,255,0.3); text-align: center; } h2 { font-size: 28px; margin-bottom: 20px; } label { font-size: 18px; } input[type="text"] { width: 100%; padding: 15px; margin: 10px 0; font-size: 18px; border: none; border-radius: 10px; } input[type="submit"] { width: 100%; padding: 15px; font-size: 20px; background: #00ffcc; border: none; border-radius: 10px; color: black; cursor: pointer; font-weight: bold; transition: 0.3s; } input[type="submit"]:hover { background: #00ffaa; transform: scale(1.05); } .submitted-text { font-size: 20px; margin: 10px 0; } </style>

"""

--- HOME PAGE (FORM) ---

@app.route('/') def form(): return render_template_string(f''' {animated_bg}

Mini Form

Name:

            <label>Class:</label>
            <input type="text" name="cls" required>

            <label>Section:</label>
            <input type="text" name="sec" required>

            <input type="submit" value="Submit">
        </form>
        <p>Scan QR to open on mobile:<br><img src="/qr" width="150"></p>
        <p>Or open link: <a href="{public_url}" target="_blank">{public_url}</a></p>
    </div>
</body>
</html>
''')

--- SERVE QR CODE ---

@app.route('/qr') def qr(): return send_file("flask_qr.png", mimetype="image/png")

--- FORM SUBMIT PAGE ---

@app.route('/submit', methods=['POST']) def submit(): name = request.form.get("name") cls = request.form.get("cls") sec = request.form.get("sec")

# Save to CSV
with open("form_data.csv", "a", newline="") as f:
    writer = csv.writer(f)
    writer.writerow([name, cls, sec])

# Print in PC terminal
print("\n----- NEW FORM SUBMISSION -----")
print(f"Name: {name}, Class: {cls}, Section: {sec}")
print("-------------------------------\n")

return render_template_string(f'''
<html>
<head>{animated_bg}</head>
<body>
    <div class="container">
        <h2>Form Submitted!</h2>
        <p class="submitted-text"><b>Name:</b> {name}</p>
        <p class="submitted-text"><b>Class:</b> {cls}</p>
        <p class="submitted-text"><b>Section:</b> {sec}</p>
        <p><a href="/">Back to form</a></p>
    </div>
</body>
</html>
''')

--- RUN SERVER ---

app.run(host="0.0.0.0", port=port)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors