HTML Form Submission

Created on September 19, 2024

python
sync

Import to edit/run function

This function demonstrates how to create a form and process a submission with CodeUpify

Function Code

html = """
<!DOCTYPE html>
<html lang="en">
<body>
    <form action="https://run.codeupify.com/r/QzZBE4P6y1" method="POST">
        <label for="yourName">Your Name:</label>
        <input type="text" id="yourName" name="yourName" required>
        <br>
        <label for="favFood">Your Favorite Food:</label>
        <input type="text" id="favFood" name="favFood" required>
        <br>
        <label for="favMusic">Your Favorite Music:</label>
        <input type="text" id="favMusic" name="favMusic" required>
        <br>
        <label for="location">Where do you live:</label>
        <input type="text" id="location" name="location" required>
        <br>
        <button type="submit">Submit</button>
    </form>
</body>
</html>"""

def handler(request):
    if request['method'] == 'GET':
        return html
    elif request['method'] == 'POST':
        data = request['body']

        favFood = data.get('favFood')
        favMusic = data.get('favMusic')
        yourName = data.get('yourName')

        response = f"You are {yourName}. You're probably hungry for {favFood}, and your favorite music is {favMusic}."
        
        return response

Run Function

Input JSON

Loading...

Output