...

View Full Version : Auto submit form in a bookmarklet



hyphen
05-28-2005, 03:12 AM
Hi

I'm trying to create a bloging bookmarklet for use with my geeklog site.
I have it functioning with a popup window that shows the content to send and allows for modifications, and there is a submit button that sends it to the blogs php script. The php script accepts the data and your left at the preview story screen, essentially the same thing as the popup i'm triggering.

I would like to remove the first "verification" stage, and just have the form autosubmit and popup the php script in a new window.

this is what i'm using now unwrapped...to do the bookmarklet it has to be one continuous line of code, to make things easier to view I formated it here

javascript:
u=document.location.href;
var t=document.title;
sr=window.getSelection();
var f='width=600,height=600,toolbar=0,location=0,directories=0,status=1,menuBar=0,scrollBars=1,resizable =1';
var s=window.open('','Title',f);with(s.document){write('
<html><title>geekloglette</title>
<body style=margin: 0px 0px 0px 0px;background-color:#FFCC00>
<form action=%22http://SITE.URL/PATH_TO_GEEKLOG_ROOT/submit.php%22 method=%22post%22>
<table border=%220%22 cellspacing=%220%22 cellpadding=%223%22>
<tr>
<td align=%22right%22>
<b>Title:</b>
</td>
<td>
<input type=%22text%22 size=%2236%22 maxlength=%2296%22 name=%22title%22 value='+t+'>
</td>
</tr>
<tr>
<td align=%22right%22>
<b>Topic:</b>
</td>
<td>
<select name=tid>
<option value=%22TOPIC1%22>TOPIC1</option>
<option value=%22TOPIC2%22>TOPIC2</option>
<option value=%22TOPIC3%22>TOPIC3</option>
</select>
</td>
</tr>
<tr valign=%22top%22>
<td align=%22right%22>
<b>Story:</b>
</td>
<td>
<textarea name=%22introtext%22 cols=%2245%22 rows=%2212%22 wrap=%22virtual%22>'+sr+'<BR><a href=%22'+u+'%22 target=_blank>'+t+'</a>
</textarea>
</td>
</tr>
<tr valign=%22top%22>
<td align=%22right%22>
<b>Post Mode:</b>
</td>
<td>
<select name=%22postmode%22>
<option value=%22html%22 selected=%22selected%22>HTML </option>
</select>
<br>
</td>
</tr>
<tr>
<td align=%22center%22 colspan=%222%22>
<input type=%22hidden%22 name=%22type%22 value=story>
<input type=%22hidden%22 name=%22uid%22 value=%222%22>
<input type=%22hidden%22 name=%22date%22 value=%22%22>
<input name=%22mode%22 type=%22submit%22 value=%22Preview%22>
</td>
</tr>
</table>
</form>
</body>
</html>');
void(close())}

i've tried naming the form "form" and adding this function

function submitForm(){
document.form.submit();
}
and calling it from the body with onload=

and i've tried reading in the data before the body call with a function like this


function autoSubmit ()
{
document.Form.title.value = '+t+';
document.Form.introtext.value = '+sr+';

document.Form.submit();
}

<body onLoad="autoSubmit();">
<form name="Form" action="site.url/submit.php">
<input type="title" value= "" />
<input type="introtextt" value= "" />
</form>
</body>

neither of these worked...the first one had no effect at all, and the second one doesn't seem to peform the action call.

any ideas?
i'm kinda stuck....

Harry Armadillo
05-28-2005, 04:21 AM
I suspect that your problems with onload not working are due to not closing the document -- document.write(...) should be followed by document.close() when creating a document from scratch.

This barebones version worked for me in Firefox:
javascript:(function(){var w=window,t=document.title,x=w.open().document;x.write("<html><body onload='document.f.submit()'><form name='f' action='http://labapache:8080/blogtest.php' method='post'><input name='title' value='"+t+"'><textarea name='introtext'>"+w.getSelection()+"<br><a href='"+w.location+"' target=_blank>"+t+"</a></textarea><input type='hidden' name='type' value='story'><input type='hidden' name='uid' value='2'><input type='hidden' name='date' value=''><input name='mode' type='submit' value='Preview'></form></body></html>");x.close()})()

hyphen
05-29-2005, 02:52 AM
Thanx
that helped alot
i went thru and restructured things, and it turns out i was forgetting to pass one variable over so the php in my blog it was coming up blank.
got it working now tho, thanx again.

now i'm going to try and get this to work in a firefox extension
cheers



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum