php
  • form-submit
  • 2010-11-27 78 views 1 likes 
    1
    <form style="text-align:center;" id="paypalform" action="https://www.paypal.com/cgi-bin/webscr" method="POST"> 
        <input type='hidden' name='cmd' value='_xclick'> 
        <input type='hidden' name='business' value='[email protected]'> 
        <input type='hidden' name='item_name' value='201001114262121'> 
        <input type='hidden' name='amount' id="amount" value='1.00'> 
        <input type='hidden' name='currency_code' value='CAD'> 
        <input type='hidden' name='return' value='http://www.xxx.com/paypal_process.php'> 
        <input type='hidden' name='invoice' value='82'> 
        <input type='hidden' name='charset' value='utf-8'> 
        <input type='hidden' name='no_shipping' value='1'> 
        <input type='hidden' name='no_note' value=''> 
        <input type='hidden' name='notify_url' value='http://www.xxx.com/return.php'> 
        <input type='hidden' name='rm' value='82'> 
        <input type='hidden' name='cancel_return' value='http://www.xxx.com/index.html'> 
    </form> 
    

    任何人都知道嗎?如何使用PHP提交表單?

    +0

    很抱歉,您需要在此處提供更多信息。你想知道如何提交到PayPal API?試試這裏:https://developer.paypal.com/ - 如果你想要一些一般的PHP表單信息,那麼在線會有大量的演示和示例代碼。 – 2010-11-27 03:45:44

    +3

    也許嘗試添加一個提交按鈕? – cdhowie 2010-11-27 03:46:18

    回答

    6
    <?php 
    if(isset($_POST['submit'])) 
    { 
        function do_post_request($url, $data, $optional_headers = null) 
        { 
         $params = array('http' => array(
             'method' => 'POST', 
             'content' => $data 
            )); 
         if($optional_headers != null) 
         { 
          $params['http']['header'] = $optional_headers; 
         } 
         $ctx = stream_context_create($params); 
         $fp = @fopen($url, 'rb', false, $ctx); 
         if (!$fp) 
         { 
          throw new Exception("Problem with $url, $php_errormsg"); 
         } 
         $response=''; 
         while (!feof($fp)) 
         { 
          $response = $response.fgets($fp); 
         } 
         if ($response === false) 
         { 
          throw new Exception("Problem reading data from $url, $php_errormsg"); 
         } 
    
         fclose($fp); 
         return $response; 
        } 
        $host = 'http://mydomain.com'; 
        $url = 'http://mydomain.com/formHandler.php'; 
        $username = 'admin'; 
        $password = '123456'; 
        $data = array ('action' => 'login','lgname' => $username, 'lgpassword' => $password, 'format' => 'txt'); 
        $data = http_build_query($data); 
        $reply = do_post_request($url, $data); 
        echo "**********Response*********<pre>"; 
        echo var_dump($reply); 
        #header('location:'.$host); 
        #exit; 
    
        } else { 
         echo '<form method="post" enctype="multipart/form-data" action="'.$_SERVER['PHP_SELF'].'"><input type="text" name="uname" /><br><input type="password" name="password" /><input type="submit" name="submit"></form>'; 
        } 
    
    ?> 
    

    試試這個

    2

    如果你想這種形式儘快在頁面加載提交,你可以將它添加到頁面的底部,如果你在使用PHP提交確定形式:

    <? 
    echo "<script type=\"text/javascript\"> 
           window.onload=function(){ 
            document.forms['paypalform'].submit(); 
           } 
         </script>"; 
    ?> 
    

    但這似乎是一個很長的路要走。你可以將JavaScript寫入頁面...也許我不確定你想要做什麼,但我想我會拋出這個。

    0

    使用JavaScript可以提交這樣的PHP代碼裏面的表格: (訣竅是在最後一行)

    $paypalURL = 'https://www.sandbox.paypal.com/cgi-bin/webscr'; 
        $paypalID = '[email protected]'; 
        $form = "<form id='paypal' action='". $paypalURL."' method='post'>"; 
        $form .='<input type="hidden" name="business" value="'. $paypalID.'">'; 
        $form .='<input type="hidden" name="cmd" value="_xclick">'; 
        $itemDetail = "Detail goes here"; 
        $orderId = 4444; 
        $totalAmountWithFee = 55; 
        $form .='<input type="hidden" name="item_name" value=" '.$itemDetail.'"> 
         <input type="hidden" name="item_number" value="'.$orderId.'"> 
         <input type="hidden" name="amount" value="'.$totalAmountWithFee.'"> 
         <input type="hidden" name="currency_code" value="USD">'; 
    
        $form .="<input type='hidden' name='cancel_return' value='http://localhost/public/cancel.php'> <input type='hidden' name='return' value='http://localhost/success.php'>"; 
        $form.="<script type=\"text/javascript\"> document.forms['paypal'].submit();</script>"; 
        echo $form; 
    

    如果某人有一個好主意,請份額。

    相關問題