//Title: cutnsend
//Public domain.
//Contributed by: YMIHere
/*
This will bypass the size limit of the GET method by
sending multiple links to datum.Topic() and building
the anwsers in the datums form_info list (in the form
of "name"="value"). For checkboxes and radio buttons,
their information will only send if they've been checked.
Call datum.CNSScript to get the script for that datum and
put it in the header of the HTML page, then call cutnsend()
whenever you want to send the information.
datum.CNSFinished() is called when the form_info list has
been completely filled out. I think you might be able to
use this with HTML forms, not real sure. =P
*/
datum
Topic(href,href_list[])
if("CUTNSEND" in href_list)
if(href_list["CUTNSEND"]=="DONE")
CNSFinished()
else
if(!form_info) form_info=new
form_info[href_list[3]]+=href_list[href_list[3]]
.=..()
var/list/form_info
proc
CNSFinished()
del form_info
CNSScript(limit=150)
return {"
<script type="text/javascript">
function cutnsend()
{
var text="";
for (form in document.forms)
{
form=document.forms\[form\];
for (i=0; i<form.length; i++)
{
if(form.elements\[i\].type!="checkbox" &&
form.elements\[i\].type!="radio" ||
form.elements\[i\].checked)
{
text=form.elements\[i\].value;
for (j=0; j<=text.length; j+=[limit])
{
var newstr=text.substr(j,[limit]);
var url="byond://?src=\ref[src];CUTNSEND;"+form.elements\[i\].name +
"=" +
newstr;
window.open(url,"_top");
}
}
}
}
window.open("byond://?src=\ref[src];CUTNSEND=DONE;","_top");
}
</script>
"}
///*
//Testing Code/Sample Implementation:
mob/verb
settings()
var/page={"<html><head><title>Settings</title>[CNSScript()]</head>
<body><form><input type="hidden" name="use" value="settings" />
Name:<br /><input type="text" name="name" value="[key]" /><br />
Description:<br /><textarea name="description" cols="15"
rows="6">[client.gender]</textarea></form><br /><input type="button"
value="Save Changes" onclick="cutnsend()" /></body></html>"}
src << browse(page,"window=settings")
preferences()
var/page={"<html><head><title>Preferences</title>[CNSScript()]</head>
<body><form><input type="hidden" name="use" value="preferences" />
Color:<input type="text" name="color" value="blue" /><br />
Bold:<input type="checkbox" name="bold" value="TRUE" />
</form><br /><input type="button" value="Save Changes"
onclick="cutnsend()" /></body></html>"}
src << browse(page,"window=preferences")
mob/CNSFinished()
if(form_info["use"]=="settings")
name=form_info["name"]
desc=form_info["description"]
src<<"Your name is now [name].\nYour desc is now <pre>[desc]."
src << browse(null,"window=settings")
else if(form_info["use"]=="preferences")
src<<"<font color=\"[form_info["color"]]\">\
[form_info["bold"]?"<b>":][name]\
[form_info["bold"]?"</b>":]</font>"
src << browse(null,"window=preferences")
// for(var/variable in form_info)
// src << "[variable] = [form_info[variable]]"
..()
//*/
ID:195077
Jan 11 2007, 3:16 pm (Edited by moderator on Mar 13 2007, 3:00 pm)
|
|
Jan 14 2007, 10:34 am
|
|
I edited your snippet to allow for you to specify an ID. This ID can be used to have multiple form submissions at the same time with absolutely no fear of things going wrong.
|
In response to Android Data
|
|
Good idea. =)
|