将表单提交重定向到另一个页面问题

时间:2017-03-18 13:12:17

标签: php wordpress forms redirect

在我的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/。因此,当我请求此路径(表单所在的位置)时,它只会重定向到example.com/user

表单控制器:

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

1 个答案:

答案 0 :(得分:1)

您需要某种钩子来提供表单的状态,并将其绑定到重定向以作用于钩子。就像将重定向作为一个函数一样,并在正确提交表单时调用该函数。像Gravity From这样的第三方插件可以为你做到这一点。如果您想要这样的付费服务,由您决定。

Sub LoopRange2()

    Dim rCell1 As Range
    Dim rCell2 As Range
    Dim rRng1 As Range
    Dim rRng2 As Range

    Dim nCol As Integer                                     'Finds week column to insert values
    nCol = Worksheets("Clube").Range("P69").Value + 5


    'Find number of pairs that played the tournment
    Dim last_pair_cell As Integer
    Dim rngX As Range

    Set rngX = Worksheets("Sheet_CSV").Range("A1:A10000").Find("Board", lookat:=xlPart)
    If Not rngX Is Nothing Then
        last_pair_cell = rngX.Row - 1
    End If



    **Set rRng1 = Worksheets("Sheet_CSV").Range(Cells(2, 9), Cells(last_pair_cell, 10))**
    'Set rRng1 = Worksheets("Sheet1").Range("I2:J20")
    Set rRng2 = Worksheets("Clube").Range("C3:C80")         'IF ERROR CHANGE C80 TO C69

    For Each rCell1 In rRng1.Cells
        For Each rCell2 In rRng2.Cells
            If rCell2.Value = rCell1.Value Then
                Worksheets("Clube").Cells(rCell2.Row, nCol).Value = Worksheets("Sheet1").Cells(rCell1.Row, 6).Value
            End If
        Next rCell2
    Next rCell1

End Sub

<script type="text/javascript">
function calculate(id){
var quantity = document.getElementById('qty'+id).value;
//alert("quantity: " + quantity);
var price = document.getElementById('price'+id).value;
//alert("price: " + price);
var disc = document.getElementById('disc'+id).value;
//alert("disc: " + disc);
var sum = (parseInt(quantity,10)*parseInt(price,10)) - (parseInt(disc,10));
document.getElementById('total'+id).value = sum;
}
</script>