All pastes #765372 Raw Edit

Luaetta test script

public lua v1 · immutable
·published 2007-11-07 23:35 UTC
rendered paste body
function onRequest(env, post)	setHeader("Content-type", "text/html") -- This is default anyway, but just for example... :)	print([[ 	<FORM action="http://localhost/test2.lua" method="post">    <P>    First name: <INPUT type="text" name="firstname"><BR>    Last name: <INPUT type="text" name="lastname"><BR>    email: <INPUT type="text" name="email"><BR>    <INPUT type="radio" name="sex" value="Male"> Male<BR>    <INPUT type="radio" name="sex" value="Female"> Female<BR>    <INPUT type="submit" value="Send"> <INPUT type="reset">    </P>    </FORM>    ]])	if post then		print(getBodyData(2))	else		for k, v in pairs(env) do			print(k, "=", v, "<br/>")		end	endendfunction form_to_table(s)	local fields = {};	for k, v in s:gmatch("&?([^=]+)=([^&]+)&?") do		fields[k] = v;	end	return fields;endfunction urldecode(s)	return (s:gsub("+", " "):gsub("%%([a-fA-F0-9][a-fA-F0-9])", setmetatable({}, { __index = function (t, k) t[k] = string.char(tonumber("0x"..k)); return t[k]; end })));end