autosend <form>

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pad4ever
Forum Newbie
Posts: 9
Joined: Wed Aug 24, 2005 3:58 am

autosend <form>

Post by pad4ever »

patrikG | Please use

Code: Select all

and

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

and

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]
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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 =/
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
pad4ever
Forum Newbie
Posts: 9
Joined: Wed Aug 24, 2005 3:58 am

Post by pad4ever »

patrikG | Please use

Code: Select all

and

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

and

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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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!');
User avatar
J_Iceman05
Forum Commoner
Posts: 72
Joined: Wed Aug 03, 2005 10:52 am
Location: Las Vegas, NV

self starting java...

Post 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>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply