我试图按条件重定向到另一个表单/页面。我在 Wordpress 4.9 中使用了 Ninja Forms (3.3. )。. 我创建了 webhook。
以下是代码
add_action( 'generate_token', 'generate_token_callback' );
/**
* @param $form_data array
* @return void
*/
function generate_token_callback( $form_data ){
global $ninja_forms_processing;
$form_id = $form_data[ 'form_id' ];
$form_fields = $form_data[ 'fields' ];
foreach( $form_fields as $field ){
$field_id = $field[ 'id' ];
$field_key = $field[ 'key' ];
$field_value = $field[ 'value' ];
// Example Field Key comparison
if( 'my_field' == $field[ 'key' ] ){
// This is the field that you are looking for.
}
}
error_log( "get token - " . $form_id, 0 );
$form_settings = $form_data[ 'settings' ];
$form_title = $form_data[ 'settings' ][ 'title' ];
error_log( "get token 2 - " . $form_id, 0 );
if($form_id == 2) {
$url = get_home_url() . "/thankyou" ;
wp_redirect( $url );
}else{
$url = get_home_url() . "/error" ;
wp_redirect( $url );
}
}
wp_redirect 不起作用。我怎样才能?
更新 - -
添加“exit();”后
但不重定向到thankyou页面。
更新 - -
由完成
https://www.inkthemes.com/how-you-can-easy-create-customized-form-in-wordpress/