Page 1 of 1
autosend <form>
Posted: Tue Sep 06, 2005 7:44 am
by pad4ever
patrikG | Please use Code: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]Hi there
is there a way to automaticly send a form?
Problem goes as follows:
I've got a form that looks like this:
Code: Select all
<form method="post" action="http://www.test.com" style="margin: 0px; padding: 0px;" name="em_newsletter">
<input type="hidden" name="guid"value="****">
<input type="hidden" name="referer" value="http://www.google.com">
<input type="hidden" name="firstname" value="whaever">
</form>
i want to send this form as soon as i connect to the page that form is on. But i don't want the user connecting to the page to see it. i don't know if that works since there is no submit button.
Thanks for the help
pad
patrikG | Please use Code: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Posted: Tue Sep 06, 2005 7:55 am
by s.dot
perhaps using a javascript yes
Code: Select all
<head>
<script type="text/javascript">
<!--
setTimeOut(wait(),1000);
function wait() {
this.form.submit();
}
//-->
</script>
</head>
<body onLoad="wait()">
something like that I suppose =/
Posted: Tue Sep 06, 2005 8:16 am
by pad4ever
patrikG | Please use Code: Select all
tags where approriate when posting code. Read: :arrow: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]i thought about using a java script myself. here's one that "should" work. unfortunatly it doesn't.
Code: Select all
<script language="JavaScript">
function submitForm()
{
document.em_newsletter.submit();
}
</script>
maybe the script isn't started. isn't there a way that the javascript starts on it's own?
patrikG | Please use Code: Select all
tags where approriate when posting code. Read: :arrow: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Posted: Tue Sep 06, 2005 9:58 am
by feyd
what about using
curl, or
fsockopen() to do the submission from php? Is this page being submitted to on your server? If so, you could just fake the submission and pass the variables to it, saving you the expense of making an unneeded http request.
Posted: Tue Sep 06, 2005 10:50 am
by timvw
With
simpletest scriptable browser this is pretty easy

) (And easy to understand imho)
Code: Select all
require_once(TVW_EXT . '/simpletest/browser.php');
// new browser
$ua =& new SimpleBrowser;
$ua->addHeader('User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6');
// goto index page
$ua->get('http://www.smscity.be/index.php');
// fill in form
$ua->setField('send', 'versturen');
$ua->setField('action', 'login');
$ua->setField('gsm', $username);
$ua->setfield('pass', $password);
$ua->setField('opslaan', 1);
// submit form
$ua->clickSubmit('Login!');
self starting java...
Posted: Wed Sep 07, 2005 11:34 am
by J_Iceman05
Code: Select all
<script language="JavaScript">
function submitForm()
{
document.em_newsletter.submit();
}
</script>
this puts the "document.em_newsletter.submit();" into a function...
functions don't start on thier own, they have to be called.
if you want to make a function. then you could do this...
Code: Select all
<script language="JavaScript">
function submitForm()
{
document.em_newsletter.submit();
}
submitForm(); //this calls the function and executes it
</script>
I think it might even be easier to just not use a function. This may be more of what you are thinking of. it automatically starts as soon as the javascript itself loads.
Code: Select all
<script language="JavaScript">
document.em_newsletter.submit();
</script>
Posted: Wed Sep 07, 2005 11:37 am
by feyd
one bit of warning about a common pitfall: do not name any field/button/whatever inside the form 'submit'
Why, you ask? Try it, you'll find out that the form will no longer submit through calling the method because you're calling the field instead.