Code: Select all
Sub PrintHeaders()
Print !"Content-type:text/html;Charset=us-ascii\n"
End Sub
Function SplitVar(query as string, arg as string) as string
Dim as string value, result
If InStr(query, arg) <> 0 Then
value = Mid(query, InStr(query, arg), len(query))
If Instr(value, "&") <> 0 Then
result = Mid(value, len(arg) + 2, Instr(value, "&") - len(arg) - 2)
Else
result = Mid(value, len(arg) + 2, len(value))
End If
Else
result = ""
End If
SplitVar = result
End Function
Function ReadStdin() as string
Dim numChars as integer
Dim postQuery as string
numChars = val(environ("CONTENT_LENGTH"))
open cons for input as #1
postQuery = space(numChars)
get #1,,postQuery
close #1
ReadStdin = postQuery
End Function
Function QueryString(arg as string) as string
If environ("REQUEST_METHOD") = "GET" Then
QueryString = SplitVar(environ("QUERY_STRING"), arg)
Else
QueryString = ""
End If
End Function
Function Post(query as string, arg as string) as string
If environ("REQUEST_METHOD") = "POST" Then
Post = SplitVar(query, arg)
Else
Post = ""
End If
End Function
'Now we can print the page content
PrintHeaders()
Print "<html>"
Print "<head>"
Print "<body>"
Print "<form id=""personal-data"" method=""post"" action=""test.exe"">"
Print "<div style=""text-align:center;"">"
Print "<h2>Fill this form with your data</h2>"
Print "First Name: <input type=""text"" name=""firstname"" /><br />"
Print "Last Name: <input type=""text"" name=""lastname"" /><br />"
Print "City: <input type=""text"" name=""city"" /><br />"
Print "Country: <input type=""text"" name=""country"" /><br />"
Print "<input type=""submit"" id=""send"" value=""Send"" />"
Print "</div></form>"
Print "<div style=""text-align:center;"">"
If environ("REQUEST_METHOD") = "POST" Then
Dim as String strPost = ReadStdin()
Print "<em>Your data was successfully receipted!</em><br>"
Print "<p>Your name is: <strong>"& Post(strPost, "firstname") &" "& Post(strPost, "lastname") &"</strong></p>"
Print "<p>And you lives on: <strong>"& Post(strPost, "city") &" - "& Post(strPost, "country") &"</strong> </p>"
Else
Print "<em>No data sent yet!</em>"
End If
Print "<div>"
Print "</body>"
Print "</head>"
Print "</html>"
Just compile as TEST.EXE and run as CGI on a webserver like TinyWeb: http://www.ritlabs.com/en/products/tinyweb/
You must only create a CGI-BIN folder into your root and there place the EXE compiled, now go to your browser and prompt http://localhost/cgi-bin/test.exe and you will see the form ready to work.
Please comment about my code!
Regards