我用单行文本字段建立了一个重力形式。我用它来检查邮编和城市。如果有人输入正确的邮政编码,它将重定向到特定的页面。另外,如果有人键入邮政编码或城市,而没有匹配的值,它也会重定向到特定的页面。我试过这个密码。但我似乎不能让它正常工作。如果我有一个数字,它可以工作,但是如果我添加多个用逗号分隔的数字,它就不工作了。如果可能的话请帮忙。
<?php
function de_gforms_confirmation_dynamic_redirect( $confirmation, $form, $entry, $ajax ) {
if ( $form['id'] == '38' ) {
if ( $entry['1'] == '89103,80205,91030' ) {
$confirmation = array( 'redirect' => 'https://google.com' );
} else if ( $entry['1'] == '90210,89554,90454' ) {
$confirmation = array( 'redirect' => 'https://yahoo.com' );
} else if ( $entry['1'] == '56678,89004,78896' ) {
$confirmation = array( 'redirect' => 'https://test.com' );
}
}
return $confirmation;
}
add_filter( 'gform_confirmation', 'de_gforms_confirmation_dynamic_redirect', 10, 4 );
?>发布于 2022-01-31 16:00:05
您需要使用or运算符“维希”而不是邮政编码数组。
<?php
function de_gforms_confirmation_dynamic_redirect( $confirmation, $form, $entry, $ajax ) {
if ( $form['id'] == '38' ) {
if ( $entry['1'] == '89103' || $entry['1'] == '80205' || $entry['1'] == '91030' ) {
$confirmation = array( 'redirect' => 'https://google.com' );
} else if ( $entry['1'] == '90210' || $entry['1'] == '89554' || $entry['1'] == '90454' ) {
$confirmation = array( 'redirect' => 'https://yahoo.com' );
} else if ( $entry['1'] == '56678' || $entry['1'] == '89004' || $entry['1'] == '78896' ) {
$confirmation = array( 'redirect' => 'https://test.com' );
}
}
return $confirmation;
}发布于 2022-02-01 13:43:38
你有很多方法可以做到这一点。我可能会尝试将您的邮政编码/重定向转换为一个关联数组(https://wtools.io/convert-csv-to-php-array),您可以这样循环:
function de_gforms_confirmation_dynamic_redirect( $confirmation, $form, $entry, $ajax ) {
$zip_group = array("1234","2345","3456");
$count_group = count($zip_group);
for($i=0;$i<$count_group;$i++){
$redirect[$i]='https://google.com';
}
$zip_condition = array_combine( $zip_group , $redirect );
if( $form['id'] == '38' ) {
foreach($zip_condition as $zip => $condition) {
if ( $entry['1'] == $zip ) {
$confirmation = array( 'redirect' => $condition );
}
}
}
return $confirmation;
}https://stackoverflow.com/questions/70928537
复制相似问题