Php Auto Submit?, Is there a way to auto submit an html form w/o using JS??

Discussion in 'PHP' started by nickjason, Jul 24, 2009.

  1. #1
    I am trying a 3rd party lead provider that needs to be able to post leads into our system. They way that they do it seems to be different than any other provider that we have had.

    I need to be able to create a php page that contains a hidden form that they can post to that will submit the form automatically using PHP. This is the code that I have. It is currently using a piece of JS but that will have to be removed.

    CODE

    <?php
    $FirstName = "{$_GET['firstname']}";
    $LastName = "{$_GET['lastname']}";
    $Email = "{$_GET['email']}";
    $HomePhone = "{$_GET['homephone']}";
    $WorkPhone = "{$_GET['workphone']}";
    $Zip = "{$_GET['zip']}";
    $Debt = "{$_GET['debt']}";
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    </head>

    <body onload="document.WebToLeadForm.submit();">
    <form action='http://www.mysite.com/anm-redirect2.php' method='post' name='WebToLeadForm' id='WebToLeadForm'>
    <input type='hidden' name='first_name' value='<?php echo $FirstName ?>' />
    <input type='hidden' name='last_name' value='<?php echo $LastName ?>' />
    <input type='hidden' name='email1' value='<?php echo $Email ?>' />
    <input type='hidden' name='phone_home' value='<?php echo $HomePhone ?>'/>
    <input type='hidden' name='phone_work' value='<?php echo $WorkPhone ?>'/>
    <input type='hidden' value='<?php echo $Debt ?>' name='total_debt_c' />
    <input type='hidden' value='<?php echo $Zip ?>' name='primary_address_postalcode' />
    </form>


    </body>
    </html>


    Any ideas?
     
    nickjason, Jul 24, 2009 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    What's the reasoning behind the second post?

    It would seem more efficient to get and process the variables and just use header("Location" ...); to send them to the necessary page.

    But to answer your question, no. The code you posted above would be the only way to do it.
     
    jestep, Jul 24, 2009 IP
  3. chandan123

    chandan123 Prominent Member

    Messages:
    11,586
    Likes Received:
    578
    Best Answers:
    0
    Trophy Points:
    360
    #3
    may be you can use GET method instead of post and make an url and forward
     
    chandan123, Jul 24, 2009 IP
  4. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #4
    you can use curl to simulate submissions, its quite normal in unit testing also...
     
    dimitar christoff, Jul 24, 2009 IP
  5. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #5
    It's not too hard either, basically handy if you need to post behind the scene to another server.

    Here's a very simple example. (in this case I'm attaching the value of code to a variable labled as e, on the target url it'll end up being $_POST['e'], its a simple query string so you could actually have "e=whatever&h=whatever")
    
    
    	$ch = curl_init();
    	curl_setopt($ch, CURLOPT_URL,$target_url);
    	curl_setopt($ch, CURLOPT_POST, 1);
    	curl_setopt($ch, CURLOPT_POSTFIELDS,"variable=".$code."&anothervar=yadayada");
    	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    	curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
    	$data = curl_exec($ch);
    	curl_close($ch);
    
    
    PHP:
    $data will contain the response back from the other server/page.
     
    kblessinggr, Jul 24, 2009 IP
    chandan123 likes this.
  6. zandigo

    zandigo Greenhorn

    Messages:
    71
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #6
    Will it be really behind the scene? Or the server itself has to wait for response from $url?

    Another thing, if echo $data, it will be the entire web page with html code (usually if the original form is being used in web browser)
     
    zandigo, Jul 24, 2009 IP
  7. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Just because the script has to wait for the server to respond, doesn't mean that it's not behind the scene.

    If you were to echo the response html, but the paths for things such as images, css, etc would be on that server, and as such html on your own domain wouldn't work quite right cuz you don't have the same files on your main server.
     
    kblessinggr, Jul 24, 2009 IP
  8. zandigo

    zandigo Greenhorn

    Messages:
    71
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #8
    I'm not quite sure about how we consider "behind the scene". To me, it would means something similar to carrying another task that will not interfere what server is doing.

    Am I right when I think that all commands following curl_exec needs to wait for the response? If that's the case, when throwing a curl function into a php file, all commands after curl_exec must be on hold. Eventually, the server still cannot carrying 2 tasks for this php file. So this will not be "behind the scene".

    I really want to know your concept about "behind the scene" and how to actually get it work with curl :).
     
    zandigo, Jul 24, 2009 IP
  9. NewTier

    NewTier Notable Member

    Messages:
    2,201
    Likes Received:
    196
    Best Answers:
    0
    Trophy Points:
    250
    #9
    Use Ajax and iframes, and referrer hiders.

    I did this and I was making $300/day from CPA leads ;)
     
    NewTier, Jul 24, 2009 IP
  10. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #10
    my concept is meaning that you don't have a visual input sent back to the user every single time. PHP can't do threading if thats what you're implying.
     
    kblessinggr, Jul 25, 2009 IP
  11. imchandan

    imchandan Guest

    Messages:
    50
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #11
    with CURL, you can do it very easily.. you can do GET or POST whatever..
     
    imchandan, Jul 25, 2009 IP
  12. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #12
    ... as shown in post #5
     
    kblessinggr, Jul 25, 2009 IP
  13. nickjason

    nickjason Peon

    Messages:
    414
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #13
    ohh that's good thanks
     
    nickjason, Jul 25, 2009 IP
  14. HivelocityDD

    HivelocityDD Peon

    Messages:
    179
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #14
    You can either use curl or you can use HTTP client code from pear to post data dynamically. If this is some thing you are trying to do.

    But the best solution if you have many things to manipulate with the data, I would suggest creating a webservice. You can make use of default soapserver for this or you can simply create it using nusoap. You can define functions and you can get the data and process it what the way you want it to.

    Thanks!!
     
    HivelocityDD, Jul 25, 2009 IP