Send form automatic

Discussion in 'PHP' started by mman, Jun 26, 2009.

  1. #1
    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
     
    mman, Jun 26, 2009 IP
  2. susan8051

    susan8051 Peon

    Messages:
    1,358
    Likes Received:
    49
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <script type="text/javascript">
    document.vote.submit();
    </script>
     
    susan8051, Jun 26, 2009 IP
  3. mman

    mman Peon

    Messages:
    50
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    It doesn't work, in body the page is redirected to the action address, and in the header nothing happens
     
    mman, Jun 26, 2009 IP
  4. susan8051

    susan8051 Peon

    Messages:
    1,358
    Likes Received:
    49
    Best Answers:
    0
    Trophy Points:
    0
    #4
    <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):
     
    susan8051, Jun 26, 2009 IP
  5. mman

    mman Peon

    Messages:
    50
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    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):
     
    mman, Jun 26, 2009 IP
  6. mman

    mman Peon

    Messages:
    50
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I have removed target="_blank" and it works in IE, it isn't blocked. But in FireFox still nothing
     
    mman, Jun 26, 2009 IP
  7. credobyte

    credobyte Peon

    Messages:
    38
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    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.
     
    credobyte, Jun 26, 2009 IP
  8. mman

    mman Peon

    Messages:
    50
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    How can I use CURL? I don't know CURL
     
    mman, Jun 26, 2009 IP
  9. credobyte

    credobyte Peon

    Messages:
    38
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #9
    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:
     
    credobyte, Jun 26, 2009 IP
    mman and susan8051 like this.
  10. mman

    mman Peon

    Messages:
    50
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #10
    mman, Jun 26, 2009 IP
  11. susan8051

    susan8051 Peon

    Messages:
    1,358
    Likes Received:
    49
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Nice one +Reps added..
     
    susan8051, Jun 26, 2009 IP
  12. mman

    mman Peon

    Messages:
    50
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #12
    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
     
    mman, Jun 26, 2009 IP
  13. credobyte

    credobyte Peon

    Messages:
    38
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #13
    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 ?
     
    credobyte, Jun 26, 2009 IP
  14. susan8051

    susan8051 Peon

    Messages:
    1,358
    Likes Received:
    49
    Best Answers:
    0
    Trophy Points:
    0
    #14
    most probaly it doesn't have Curl enabled try phpinfo();
    and check if it has curl support.. if not try contacting your host..
     
    susan8051, Jun 26, 2009 IP
  15. mman

    mman Peon

    Messages:
    50
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #15
    I have enabled CURL, but it isn't sending data it only show my the action page
     
    mman, Jun 26, 2009 IP
  16. credobyte

    credobyte Peon

    Messages:
    38
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #16
    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 :p ) ?
     
    credobyte, Jun 26, 2009 IP
  17. mman

    mman Peon

    Messages:
    50
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #17
    it doesn't redirect it is the same address but it shows the action address and it doesn't register the page
     
    mman, Jun 26, 2009 IP
  18. credobyte

    credobyte Peon

    Messages:
    38
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #18
    <?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 .. ).
     
    credobyte, Jun 26, 2009 IP
  19. mman

    mman Peon

    Messages:
    50
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #19
    it shows the action page as if it receives the data but it doesn't register the vote
     
    mman, Jun 26, 2009 IP
  20. credobyte

    credobyte Peon

    Messages:
    38
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #20
    Check for PM ;)
     
    credobyte, Jun 26, 2009 IP