Learning

Learning projects

Python : HTML Form with button to navigate

Updated submit.py (in /cgi-bin/)
python
Copy code
#!/bin/python3

import cgi
import cgitb

# Enable error display (helpful for troubleshooting)
cgitb.enable()

# Print the content-type header
print("Content-Type: text/html\n")

# Retrieve form inputs
form = cgi.FieldStorage()
url = form.getvalue('url')

# Generate HTML with a meta refresh to navigate to the provided URL
print(f"""
<html>
<head>
    <title>Redirecting...</title>
    <meta http-equiv="refresh" content="0;url={url}" />
</head>
<body>
    <p>If you are not redirected, <a href="{url}">click here</a>.</p>
</body>
</html>
""")