cURL not sending form entries

Discussion in 'PHP' started by tableman, Apr 17, 2007.

  1. #1
    In a form there are entries like this:

    <input type="text" name="first_name" size="24" />
    <input type="text" name="last_name" size="24" />
    
    <input type="hidden" name="must_have" value="12345" />
    
    <input type="hidden" name="recipient" value="myemail@comcast.net" />
    <input type="hidden" name="redirect" value="http://mywebsite.com" />
    <input type="hidden" name="subject" value="Topic In Question" />
    Code (markup):
    When the action in the form is set to go directly to the receiving file like this:

    <form method="post" action="http://theirwebsite/receive.jsp" name="health">
    Code (markup):
    everything works. The entries are received by http://theirwebsite/receive.jsp.

    However, I need to use a separate file to send the form entries, so the action is set like this:

    <form method="post" action="http://mywebsite/separate.php" name="health">
    Code (markup):
    Code in http://mywebsite/separate.php is like this:

    <?php
    $siteUrl="http://theirwebsite/receive.jsp/";
    $variablesToPost = array
    (
    	"first_name",
    	"last_name",
            "must_have",
            "recipient",
    	"redirect",
    	"subject"
    );
    $postData = "";
    foreach($variablesToPost as $variable)
    {
    $postData = $variable.htmlspecialchars($_REQUEST[$variable]);
    $postData = encodeQueryString($postData); 
    }
    
    $curl = curl_init();   
    curl_setopt($curl, CURLOPT_URL, $siteUrl); 
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
    curl_exec ($curl);
    curl_close ($curl);
    
    ?>
    Code (markup):
    The entries can be printed from the separate file, so I know they get there.

    All spelling has been checked carefully. All hidden fields required by the destination file are listed in the array.

    The values are now not received by http://theirwebsite/receive.jsp, so something must be wrong with the code.

    Any suggestions?
     
    tableman, Apr 17, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    foreach($variablesToPost as $variable)
    {
    $postData = $variable.htmlspecialchars($_REQUEST[$variable]);
    $postData = encodeQueryString($postData); 
    }
    
    PHP:
    $postData gets overwritten with each loop. Try this instead:

    
    $postData= array();
    foreach($variablesToPost as $variable)
    {
       $postData[] = $variable . '=' . htmlspecialchars($_REQUEST[$variable]);
    }
    
    $postData = encodeQueryString(implode('&', $postData)); 
    
    
    PHP:
     
    nico_swd, Apr 17, 2007 IP
  3. tableman

    tableman Peon

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for that suggestion, nico_swd.

    However, the code still does not forward the values.

    It now looks like this:

    <?php 
    $siteUrl="http://theirwebsite/receive.jsp/"; 
    $variablesToPost = array 
    (
    "first_name", 
    "last_name", 
    "must_have", 
    "recipient", 
    "redirect", 
    "subject"
    );
    $postData= array();
    foreach($variablesToPost as $variable)
    {
       $postData[] = $variable . '=' . htmlspecialchars($_REQUEST[$variable]);
    }
    
    $postData = encodeQueryString(implode('&', $postData));
    
    $curl = curl_init();   
    curl_setopt($curl, CURLOPT_URL, $siteUrl); 
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
    curl_exec ($curl);
    curl_close ($curl);
    ?>
    Code (markup):
     
    tableman, Apr 17, 2007 IP
  4. chirayu

    chirayu Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi all,

    I am looking for working auto form fill up script. Can you help me out. If you can provide me, contact me at .

    Thanks a lot in advance.
     
    chirayu, Jun 5, 2008 IP