0

フォームを送信するときに非常に頻繁に状況が発生します。ユーザーから注文を受けるフォームがあり、フォームを送信した後、ユーザーは支払いのためにPayPalにかかります。問題は、どうすればユーザーを PayPal にリダイレクトできるかということです。j クエリの $.post 関数、JavaScript ダブル アクションの送信、php クエリ文字列のリダイレクトなど、ほぼすべての解決策を試しましたが、誰も助けてくれませんでした。私を助けてくれる皆さんへのささやかなお願いです。解決策を教えてください。

追加: フォームはカスタムで、WordPress にデータを保存するためのテンプレートを作成しました。フォームアクションのパスをデータベースパスに変更すると、データベースに送信され、PayPalパスに変更すると、データベースではなくPayPalに送信されます。

4

2 に答える 2

1

フォームのデータを処理した後、PayPal にリダイレクトする非常に簡単な方法があります。したがって、このエントリの原則のみに従う必要があります。

まず、プラグインのコードから WordPress init にアクションを設定しました。

add_action( 'init', 'my_init');

ここで、'my_init' 関数を実装します。

if( !function_exists( 'my_init' ) ){ // Use function_exists to avoid conflicts
    function my_init(){
        if( $_POST[ 'unique_variable' ]){ // A form field to identify we are processing the form
        //...process here your form
        // and then print the form to be redirected to PayPal
        ?>
        <form action="https://www.paypal.com/cgi-bin/webscr" name="myform" method="post">
           <input type="hidden" name="business" value="seller@email.com" />
       <input type="hidden" name="item_name" value="Product Name" />
           <input type="hidden" name="item_number" value="Product Number" />
       <input type="hidden" name="amount" value="10" />
       <input type="hidden" name="currency_code" value="USD" />
       <input type="hidden" name="lc" value="EN" />

       <input type="hidden" name="return" value="URL to the product after check the payment" />
       <input type="hidden" name="cancel_return" value="URL to use if user cancel the payment process" />
       <input type="hidden" name="notify_url" value="URL of IPN in your website to check the payment" />

       <input type="hidden" name="cmd" value="_xclick" />
       <input type="hidden" name="page_style" value="Primary" />
       <input type="hidden" name="no_shipping" value="1" />
       <input type="hidden" name="no_note" value="1" />
       <input type="hidden" name="bn" value="PP-BuyNowBF" />
       <input type="hidden" name="ipn_test" value="1" />
        </form>
        <script type="text/javascript">document.myform.submit();</script>
        <?php
        exit; // It is very important stop the WordPress in this point
        }

    }
}

PayPal フォーム フィールドの値を、電子メール、IPN への URL、キャンセルおよび返品ページ、製品の名前、番号、および請求金額で変更する必要があります。

PayPal フォームを印刷した後の "exit" 文に注意してください。PHP の実行、document.myform.submit(); を停止する必要があります。読み込まれた後に PayPal フォームを送信します。

このテーマの優れた出発点は、プレミアム バージョンのプラグイン計算フィールド フォーム ( http://wordpress.org/plugins/calculated-fields-form/ )です。

;-) エリコ

于 2013-11-05T15:11:13.787 に答える
1

同様のコードが機能するはずです。subscriptionFrm はフォームの ID です。私の場合、index.php は、サーバー側の処理に関するステータスを含む JSON 文字列を返します (JSON 文字列は eval で解析されます)。もちろん、すべての PayPal 非表示フィールドを現在のフォームに追加する必要があります。

$(document).ready(function () {

$('#subscriptionFrm input[type="submit"]').click(関数 () {

          $.post('index.php', $('#subscriptionFrm').serialize()).done(function (r) {
                  var result = eval('(' + r + ')');
                  
                  /* Check result from your PHP code */
                  
                  
                  $('#subscriptionFrm').attr('action', 'https://www.paypal.com/cgi-bin/webscr');
                  $('#subscriptionFrm').submit();
          });
          
          return false;           }); });
于 2013-11-05T08:24:49.923 に答える