Please don't look at these unless you are really struggling!
<html> <head> <title>Form sample</title> </head> <body> <h1>Sequence analysis</h1> <p>Enter your name and the sequence to be analyzed, then select the sequence type and types of analysis to be performed.</p> <h2>Enter your data...</h2> <!-- For Birkbeck you will need to change the action='....' to http://http://student.cryst.bbk.ac.uk/cgi-bin/cgiwrap/USERNAME/form.cgi replacing USERNAME as appropriate --> <form action='./form.cgi' method='post'> <p><b>Name:</b><br /> <input name='name' type='text' size='49' /></p> <p><b>Sequence:</b><br /> <textarea name='sequence' cols='40' rows='10'></textarea></p> <p><b>Sequence type:</b> <input name='seqtype' value='protein' type='radio' checked='checked' />Protein <input name='seqtype' value='dna' type='radio' />DNA </p> <p><b>Analysis types:</b><br /> <input name='antype' type='checkbox' value='hydrophobicity' />Hydrophobicity<br /> <input name='antype' type='checkbox' value='accessibility' />Accessibility<br /> <input name='antype' type='checkbox' value='secstruc' />Secondary Structure<br /> </p> <p> <input type='submit' value='Submit' /> <input type='reset' value='Clear form' /> </p> </form> </body> </html>
#!/usr/bin/env python3 import cgi; # Useful debugging output import cgitb cgitb.enable() # Send errors to browser # cgitb.enable(display=0, logdir="/path/to/logdir") # log errors to a file # Print the HTML MIME-TYPE header print ("Content-Type: text/html\n") # Now grab the content of the form form = cgi.FieldStorage() name = form["name"].value seq = form["sequence"].value seqtype = form.getvalue("seqtype") # Alternative way of doing the same thing antype = form.getlist("antype") html = "<html>\n" html += "<head>\n" html += "<title>Sequence analysis results</title>\n" html += "</head>\n\n" html += "<body>\n" html += "<h1>Sequence analysis results</h1>\n" html += "<p>Data were submitted by: <b>" + name + "</b></p>\n" html += "<h2>Your sequence was:</h2>\n" html += "<pre>\n" html += seq html += "</pre>\n" html += "<p>This is a <b>" + seqtype + "</b> sequence.</p>\n" html += "<h2>Analysis</h2>\n" html += "<p>The following forms of analysis are to be performed:</p>\n" html += "<ul>" for a in antype: if a == "hydrophobicity": html += "<li>Hydrophobicity profile</li>\n" if a == "accessibility": html += "<li>Accessibility prediction</li>\n" if a == "secstruc": html += "<li>Secondary structure prediction</li>\n" html += "</ul>\n" html += "</body>\n" html += "</html>\n" print (html)