2017-03-18 8 views
0

私のWordpressサイトでは、フォームを送信した後、example.com/userのようなページにリダイレクトしたいと思います。ここフォーム提出を別のページにリダイレクトする

:method:POST 
:path:/dash/product/edit/ 

は、フォームの始まりです:

<!-- Submission Form --> 
<form method="post" action="" id="wcv-product-edit" class="wcv-form wcv-formvalidator"> 

、フォームの終わり:

<?php WCVendors_Pro_Product_Form::form_data($object_id, $post_status); ?> 
      <?php WCVendors_Pro_Product_Form::save_button($title); ?> 

私は、フォームのこの内部を置くことを試みた:

header('Location: http://www.example.com/user'); 

しかし、これはフォームがあるページ全体をリダイレクトしますフォーム送信なしでexample.com/userに配置されています。フォームは次のパスにあります:/dash/product/edit/

public function process_submit() { 

     if (! isset($_POST[ '_wcv-save_product' ]) || !wp_verify_nonce($_POST[ '_wcv-save_product' ], 'wcv-save_product') || !is_user_logged_in()) { 
      return; 
     } 

     $can_submit_live  = WC_Vendors::$pv_options->get_option('can_submit_live_products'); 
     $current_post_status = isset($_POST[ 'post_status' ]) ? $_POST[ 'post_status' ] : ''; 
     $can_edit_approved  = WC_Vendors::$pv_options->get_option('can_edit_approved_products'); 
     $trusted_vendor   = (get_user_meta(get_current_user_id(), '_wcv_trusted_vendor', true) == 'yes') ? true: false; 
     $untrusted_vendor  = (get_user_meta(get_current_user_id(), '_wcv_untrusted_vendor', true) == 'yes') ? true: false; 

     if ($trusted_vendor) $can_submit_live = true; 
     if ($untrusted_vendor) $can_submit_live = false; 


     $text = array('notice' => '', 'type' => 'success'); 

は、どのように私はそれだけで成功した後、フォームを送信example.com/userにリダイレクトすることができます:私は(フォームが配置されている)、このパスを要求するときだから、ちょうど

フォームコントローラをexample.com/userにリダイレクト?

答えて

1

フックには、フォームのステータスを通知し、フックに作用するリダイレクトにバインドする必要があります。リダイレクションを関数にすると、フォームが正しく送信されたときにその関数を呼び出すようにします。あなたのためにこれを行うことができるGravity Fromのようなサードパーティのプラグインがあります。このような有料サービスが必要な場合は、あなた次第です。

public function process_submit() { 
 

 
    if (! isset($_POST[ '_wcv-save_product' ]) || !wp_verify_nonce($_POST[ '_wcv-save_product' ], 'wcv-save_product') || !is_user_logged_in()) { 
 
    return; 
 
    } 
 

 
    $can_submit_live  = WC_Vendors::$pv_options->get_option('can_submit_live_products'); 
 
    $current_post_status = isset($_POST[ 'post_status' ]) ? $_POST[ 'post_status' ] : ''; 
 
    $can_edit_approved  = WC_Vendors::$pv_options->get_option('can_edit_approved_products'); 
 
    $trusted_vendor   = (get_user_meta(get_current_user_id(), '_wcv_trusted_vendor', true) == 'yes') ? true: false; 
 
    $untrusted_vendor  = (get_user_meta(get_current_user_id(), '_wcv_untrusted_vendor', true) == 'yes') ? true: false; 
 

 
    if ($trusted_vendor) { 
 
    header('Location: http://www.example.com/user'); 
 
    }else { 
 
    # code... 
 
    } 
 

 

 
    $text = array('notice' => '', 'type' => 'success'); 
 
}

public function process_submit() { 
 

 
    if (! isset($_POST[ '_wcv-save_product' ]) || !wp_verify_nonce($_POST[ '_wcv-save_product' ], 'wcv-save_product') || !is_user_logged_in()) { 
 
     return; 
 
    } 
 

 
    $can_submit_live  = WC_Vendors::$pv_options->get_option('can_submit_live_products'); 
 
    $current_post_status = isset($_POST[ 'post_status' ]) ? $_POST[ 'post_status' ] : ''; 
 
    $can_edit_approved  = WC_Vendors::$pv_options->get_option('can_edit_approved_products'); 
 
    $trusted_vendor   = (get_user_meta(get_current_user_id(), '_wcv_trusted_vendor', true) == 'yes') ? true: false; 
 
    $untrusted_vendor  = (get_user_meta(get_current_user_id(), '_wcv_untrusted_vendor', true) == 'yes') ? true: false; 
 

 
    if ($trusted_vendor) $can_submit_live = true; 
 
    if ($untrusted_vendor) $can_submit_live = false; 
 

 
    if ($can_submit_live) { 
 
     header('Location: http://www.example.com/user'); 
 
    }else { 
 
     # code... 
 
    } 
 
    
 
    $text = array('notice' => '', 'type' => 'success'); 
 
}

+0

私はプラグインを使用しますが、私はプラグインの一部である形式を使用する必要があります:あなたはフォームを書いているので、/ –

+1

をし、あなた自身の検証。妥当性検査の失敗または成功の結果が得られますか?あなたがすれば 'header( 'Location:http://www.example.com/user');'を 'if文 'でバインドすることができます。リダイレクションは何も起こりません。スタンドアロンの機能で、デフォルトのフローを中断するものがないためです。 –

+0

こんにちは、私の質問を編集し、送信ボタンのif文でフォームコントローラを追加しました。チェックアウトしてください。 –

関連する問題