Wordpress wp_insert_post在移动设备上多次触发

时间:2018-07-19 12:06:06

标签: php wordpress wordpress-theming

我在Wordpress上构建了一个自定义的前端多页捐赠表单,通过页面中的会话变量保存数据。然后,我使用save_post挂钩运行函数,以在提交表单后将用户重定向到在线支付门户。问题是,当用户通过移动设备访问表单时,函数wp_insert_post会多次触发。

这是我在php页面上用于处理表单数据的代码。

        .section .rodata
        .globl input_wav
input_wav:
        .incbin "input.wav"
        .globl input_wav_size
input_wav_size:
        .long . - input_wav

以下是使用save_post将用户重定向到外部付款站点的代码:

<?php
header('Cache-Control: no cache'); //no cache
session_cache_limiter('private_no_expire'); // works
//session_cache_limiter('public'); // works too
//let's start the session
session_start();

require_once 'library/HTMLPurifier.auto.php';
$config = HTMLPurifier_Config::createDefault();
$purifier = new HTMLPurifier($config);


//LISTING ALL VARIABLES AVAILABLE FROM FRONTEND FORM
$negara = $_SESSION['negara'];
$binatang = $_SESSION['binatang'];

if($_SESSION['ekor']) {
    $ekorBahagian = $_SESSION['ekor'];
} else {
    $ekorBahagian = $_SESSION['bahagian'];
}

$nama1 = $_SESSION['nama'];
$kp1 = $_SESSION['kp'];
$telefon1 = $_SESSION['telefon'];
$emel1 = $_SESSION['emel'];
$alamat11 = $_SESSION['alamat1'];
$alamat21 = $_SESSION['alamat2'];
$poskod1 = $_SESSION['poskod'];
$bandar1 = $_SESSION['bandar'];
$negeri1 = $_SESSION['negeri'];
$peserta1 = $_SESSION['peserta'];
$kempen = $_POST['kempen'];
$bank = $_POST['bank'];

if($telefon1) {
    $mobile = preg_replace("/[^0-9]/", "", $telefon1);
    $custTel = $mobile;
    $custTel2 = substr($mobile, 0, 1);
    if ($custTel2 == '+') {
        $custTel3 = substr($mobile, 1, 1);
        if ($custTel3 != '6') {
            $custTel = "+6" . $mobile;
        }
    } elseif ($custTel2 == '6') {
    } else {
        if ($custTel != '') {
            $custTel = "+6" . $mobile;
        }
    }
}


//purifying the texts
$nama = $purifier->purify($nama1);
$kp = $purifier->purify($kp1);
$telefon = $purifier->purify($custTel);
$emel = $purifier->purify($emel1);
$alamat1 = $purifier->purify($alamat11);
$alamat2 = $purifier->purify($alamat21);
$poskod = $purifier->purify($poskod1);
$bandar = $purifier->purify($bandar1);
$negeri = $purifier->purify($negeri1);
$peserta = $purifier->purify($peserta1);

if($_SESSION['ekor'])   { 
    $bil = $_SESSION['ekor']; //capturing bilangan ekor into a var
    switch ($_SESSION['negara']){
    case 'Malaysia':
        $jumlahHarga = $bil*(650*7);
        break;
    case 'ASEAN':
        $jumlahHarga = $bil*(450*7);
        break;
    case 'Timur Tengah':
        $jumlahHarga = $bil*(1300*7);
        break;
    case 'Afrika':
        $jumlahHarga = $bil*(350*7);
        break;
    default:
    } 
} else { 
    $bil = $_SESSION['bahagian']; //capturing bilangan bahagian into a var
    switch ($_SESSION['negara']){
    case 'Malaysia':
        $jumlahHarga = $bil*650;
        break;
    case 'ASEAN':
        $jumlahHarga = $bil*450;
        break;
    case 'Timur Tengah':
        $jumlahHarga = $bil*1300;
        break;
    case 'Afrika':
        $jumlahHarga = $bil*350;
        break;
    default:
    } 
}



$post = array(
    'post_title' => wp_strip_all_tags( $nama ),
    'post_status' => 'publish', 
    'post_type' => 'qurban',
    'meta_input' => array(
        'pilihan_negara' => $negara,
        'pilihan_lembu' => $binatang,
        'bilangan_ekorbahagian' => $ekorBahagian,
        'jumlah_bayaran' => $jumlahHarga,
        'nama_penuh' => $nama,
        'nombor_kad_pengenalan' => $kp,
        'nombor_telefon' => $telefon,
        'emel' => $emel,
        'alamat_rumah_1' => $alamat1,
        'alamat_rumah_2' => $alamat2,
        'poskod' => $poskod,
        'bandar' => $bandar,
        'negeri' => $negeri,
        'senarai_nama_peserta' => $peserta,
        'bank' => $bank,
        'kempen' => $kempen

    )
);
$post_id = wp_insert_post($post);

get_header(); 
?>



<?php 
get_footer();

?>

我是Wordpress开发的新手,请帮忙。

1 个答案:

答案 0 :(得分:0)

发现了错误。这与支付网关如何处理手机号码有关。我在数字前面添加了一行,以添加“ +”,并且复制停止了。

if($telefon1) {
    $mobile = preg_replace("/[^0-9]/", "", $telefon1);
    $custTel = $mobile;
    $custTel2 = substr($mobile, 0, 1);
    if ($custTel2 == '+') {
        $custTel3 = substr($mobile, 1, 1);
        if ($custTel3 != '6') {
            $custTel = "+6" . $mobile;
        }
    } elseif ($custTel2 == '6') {
        $custTel = "+" . $mobile;        //added this line.
    } else {
        if ($custTel != '') {
            $custTel = "+6" . $mobile;
        }
    }
}