how to store html form data into file
Question: My HTML code:

    
    
    <html>
    <head>
    <title>INFORMATION</title>
    </head>
      <body>
        <form action = "/cgi-bin/test.py" method = "post">
            FirstName:
            <input type = "text" name = "firstname" /><br>
            LastName:
            <input type = "text" name = "lastname" /><br>
    
            <input type = "submit" name = "submit "value = "SUBMIT">
            <input type = "reset" name = "reset" value = "RESET">
            </form>
       </body>
    

My PYTHON CODE (test.py) which is in cgi-bin directory:

    
    
    #!usr/bin/python
    
    form = web.input()
    print form.firstname
    print form.lastname
    

what should i do to store html data in some file ??


Answer: Just write it to a file!

    
    
    #!usr/bin/python
    
    import cgi
    form = cgi.FieldStorage()
    with open ('fileToWrite.txt','w') as fileOutput:
        fileOutput.write(form.getValue('firstname'))
        fileOutput.write(form.getValue'(lastname'))
    

Oh, and you need to have write permission into the file. So for example if you
are running apache, `sudo chown www-data:www-data fileToWrite.txt` should do
it.

