+ Reply to Thread
Results 1 to 3 of 3

Thread: php form submission

  1. #1
    Tenant is offline x10Hosting Member Tenant is an unknown quantity at this point
    Join Date
    Jan 2009
    Posts
    13

    php form submission

    I have been working on the following code to automatally submit data to the next page. I do not want my visitors to have to click a next button. I cant find where I am going wrong. I have upgraded my php to moderate do I need to go higher or is it a fault in my coding.

    Code:
            //create array of data to be posted
            $post_data['business'] = $business;
            $post_data['owner'] = $owner;
            $post_data['address'] = $address;
            $post_data['city'] = $city;
            $post_data['state'] = $state;
            $post_data['zip'] = $zip;
            $post_data['con'] = $number;
            $post_data['page_id'] = $page_id;
            
            //traverse array and prepare data for posting (key1=value1)
            foreach ( $post_data as $key => $value) {
            $post_items[] = $key . '=' . $value;
            }
            
            //create the final string to be posted using implode()
            $post_string = implode ('&', $post_items);
            
            //create cURL connection
            $curl_connection = curl_init('http://www.mysite.com/comments.php');
            
            //set options
            curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
            curl_setopt($curl_connection, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)');
            curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
            
            //set data to be posted
            curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
            
            //perform our request
            $result = curl_exec($curl_connection);
            
            //show information regarding the request
            print_r(curl_getinfo($curl_connection));
            echo curl_errno($curl_connection) . '-' . curl_error($curl_connection);
            
            //close the connection
            curl_close($curl_connection);

    The page is displaying

    Array ( [url] => http://www.mysite.com/comments.php [content_type] => text/html [http_code] => 200 [header_size] => 150 [request_size] => 337 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.114647 [namelookup_time] => 0.032037 [connect_time] => 0.032142 [pretransfer_time] => 0.03215 [size_upload] => 131 [size_download] => 6777 [speed_download] => 59111 [speed_upload] => 1142 [download_content_length] => 0 [upload_content_length] => 0 [starttransfer_time] => 0.105818 [redirect_time] => 0 ) 0-

  2. #2
    Scoochi2's Avatar
    Scoochi2 is offline x10 Sophmore Scoochi2 is an unknown quantity at this point
    Join Date
    Aug 2008
    Location
    Southport!
    Posts
    185

    Re: php form submission

    um.. how about something along the lines of the following?
    Of course, it only works for JS browsers, others will actually have to click the button.

    The example below will submit the data straight away. It could easily be changed to submit after a certain amount of time, or at another event.
    The next page will need to have $post_data = unserialize($_POST['data']); and then continue with all the data as-was.
    PHP Code:
    <?php
    //create array of data to be posted
    $post_data['business'] = $business;
    $post_data['owner'] = $owner;
    $post_data['address'] = $address;
    $post_data['city'] = $city;
    $post_data['state'] = $state;
    $post_data['zip'] = $zip;
    $post_data['con'] = $number;
    $post_data['page_id'] = $page_id;

    $post_data serialize($post_data);

    echo 
    '<form action="http://www.mysite.com/comments.php" method="post" name="form">
    <input type="hidden" name="data" value="'
    .$post_data.'">
    <noscript><input type="submit" value="Submit"></noscript>
    </form>'
    ;
    ?>
    <script type='text/javascript'>
    document.form.submit();
    </script>
    Last edited by Scoochi2; 02-06-2009 at 04:15 PM.
    If anyone can see it, my post was meant for anyone who reads it. Don't take it personally or think I'm being condescending... :nuts:

  3. #3
    xav0989's Avatar
    xav0989 is offline Community Public Relation xav0989 is just really nice
    Join Date
    Jul 2008
    Location
    ifk
    Posts
    4,438

    Re: php form submission

    @tenant: try to use cURL the less times possible. it may not be supported by all hosts.
    Xavier L | Community Public Relations Manager (Free Hosting Support)
    █ Yes, my position is too cool to even exist!
    How am I helping? Rate this post by clicking the icon below! (this is even better than "liking" a post)
    Terms of Service | Acceptable Use Policy | x10Hosting Wiki

+ Reply to Thread

Similar Threads

  1. Simple PHP Email Sending Form
    By dquigley in forum Programming Help
    Replies: 10
    Last Post: 12-13-2008, 02:33 PM
  2. Upload problem with my php form... Please help!
    By uplinked in forum Free Hosting
    Replies: 6
    Last Post: 12-12-2008, 09:13 AM
  3. Form to email using PHP scripting
    By jayuk666 in forum Free Hosting
    Replies: 2
    Last Post: 10-28-2008, 05:49 AM
  4. How do I protect my form in php??
    By bunglebrown in forum Programming Help
    Replies: 4
    Last Post: 09-23-2008, 10:08 AM
  5. PHP Contact Form Help
    By KeybladeSephi in forum Programming Help
    Replies: 5
    Last Post: 04-02-2008, 11:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers