Hi I want to send a form when a page loads, I have tried everything but with no success This is the code for the form Code: <form name="vote" action="http://www.mysite.com/vote.php" method="POST"> <input type="submit" name="vote" value="1" > <input type="submit" name="vote" value="Vote1" > </form> Code (markup): Can someone help my
It doesn't work, in body the page is redirected to the action address, and in the header nothing happens
<html> <head> <title> hello </title> <script type="text/javascript"> function vote() { document.vote.submit(); } </script> </head> <body onload="vote()"> <form name="vote" action="http://www.mysite.com/vote.php" method="POST"> <input type="submit" name="vote" value="1" > <input type="submit" name="vote" value="Vote1" > </form> </body> </html> Code (markup):
It doesn't work it only loads the action page. This code work only in IE as a pop up that is blocked, if it I allow it it works but in FireFox nothing happens <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Checkout </title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script type="text/javascript" language="javascript"> function submitform(){ document.getElementById('vot').submit(); } </script> </head> <body onload="submitform()"> <form name="vote" action="http://www.mysite.com/vote.php" method="POST" target="_blank"> <input type='hidden' name='vote' value='1'> <input type='hidden' name='vote' value='Vote1'> </form> <script type="text/javascript" language="javascript"> document.getElementById('vote').submit(); </script> </body> </html> Code (markup):
What's the point of auto-submiting form ? Use CURL and you'll get what you want ( most probably, even more ). Instead of instant redirect to somewhere, CURL let's you to pass/receive data without leaving your page.
Change URL and you are ready to go : <?php $vote = 1; $postfields = "vote=$vote"; $ch = curl_init(); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/cookie"); curl_setopt($ch, CURLOPT_URL, "http://www.mysite.com/vote.php"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); curl_exec($ch); curl_close($ch); ?> PHP:
Can I find out what is the the form link, something like http://www.mysite.com/vote.php?value=vote&value=1 ?
CURL gives this error Fatal error: Call to undefined function curl_init() in /www/site.com/g/o/o/site/htdocs/vote.php on line 5
You need to enable curl ( php.ini ). Actually, can you show the PHP code of your landing page ( vote page) ? Are you sure that submit button will pass the right value ?
most probaly it doesn't have Curl enabled try phpinfo(); and check if it has curl support.. if not try contacting your host..
Are you sure ? CURL does not do permanent redirects and you can't see anything without receiving data into a variable and printing it out ( echo or print ). Looks like you or your server does something new for me ! ** Don't mind in sharing the target URL ( I don't think that you own mysite.com ) ?
it doesn't redirect it is the same address but it shows the action address and it doesn't register the page
<?php $vote = 1; $postfields = "vote=$vote"; $ch = curl_init(); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/cookie"); curl_setopt($ch, CURLOPT_URL, "http://www.mysite.com/vote.php"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); $data = curl_exec($ch); curl_close($ch); echo $data; ?> PHP: This will show you the target page as if you would submit it manually. Without receiving data into a variable and printing it out, you should see a white page ( last example ). As you don't want to share the target url, I can't be sure about what I'm doing ( form, landing page .. ).