亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 Conatct Form 7 WP 中檢查復選框是否被選中

如何在 Conatct Form 7 WP 中檢查復選框是否被選中

PHP
小唯快跑啊 2023-06-18 16:20:20
我是 wordpress 的新手。我已經使用聯系表 7 在 wordpress 頁面中創建了表單。在提交表單數據之后,我正在處理 functions.php 文件中的數據。最近我在我的表單中添加了新的單個復選框。這是我的疑問,現在我必須根據選中/未選中的復選框編寫條件。這是我的表單代碼    <div class="col-md-6">        <label> Full Name <span class="required">*</span></label>        [text* fullname]    </div>    <div class="col-md-6">        <label> Mobile No <span class="required">*</span></label>        [tel* mobno]    </div>     <div class="col-md-6">        <label> Car Model <span class="required">*</span></label>        [text* carmodel]    </div>    <div class="col-md-6">        [checkbox next_service_date_chk "I don't know my Next Scheduled Service Date"]    </div>    <div class="col-md-6">        [submit id:submit "Submit"]    </div></div>我的functions.php文件代碼function serviceform( $contact_form ) {  $id = $contact_form->id;  $submission = WPCF7_Submission::get_instance();    if ( $submission ) {        $posted_data = $submission->get_posted_data();    }  if ( '8371' == $id ) {    $name =  $posted_data['fullname'];      $carmodel =  $posted_data['carmodel'];     $mobno =  $posted_data['mobno'];     $next_service_date_chk =$posted_data['next_service_date_chk'];    if($next_service_date_chk == true){     $message1 = urlencode("custome message one");    }    else{     $message1=urlencode("custome message two");    }    //sms to customer    file_get_contents('http://hpsms.dial4sms.com/api/v4/?api_key=xxxxxxxxxxxxxxxxxxxxx&method=sms&message='.$message1.'&to='.$mobno.'&type=2&sender=XXXXXX');}}add_filter( 'wpcf7_support_html5_fallback', '__return_true' );
查看完整描述

1 回答

?
慕絲7291255

TA貢獻1859條經驗 獲得超6個贊

嘗試這樣做,因為您的復選框作為數組返回。你正在做的是定義它是否有價值,這是某種東西。

此外,應該使用CF7 Docs方法而不是對象的值來獲取聯系表單 7 對象

/* Don't do this, since id property is no longer accessible. */

$id = $contact_form->id; // Wrong.


/* Use id() method instead. */

$id = $contact_form->id();

更新功能


function serviceform( $contact_form ) {

? // Use function id(); to get id of object $contact_form? ??

? if ( '8371' !== $contact_form->id() ) return;

? $submission = WPCF7_Submission::get_instance();

? ? if ( $submission ) {

? ? ? ? $posted_data = $submission->get_posted_data();

? ? }

? ? $name =? $posted_data['fullname'];??

? ? $carmodel =? $posted_data['carmodel'];?

? ? $mobno =? $posted_data['mobno'];?


? ? // Checkbox is returned as array. Check if empty.

? ? $next_service_date_chk = !empty($posted_data['next_service_date_chk'][0]) ? true : false;


? ? if($next_service_date_chk == true){

? ? ? ? $message1 = urlencode("custome message one");

? ? }

? ? else{

? ? ? ? $message1=urlencode("custome message two");

? ? }


? ? //sms to customer

? ? file_get_contents('http://hpsms.dial4sms.com/api/v4/?api_key=xxxxxxxxxxxxxxxxxxxxx&method=sms&message='.$message1.'&to='.$mobno.'&type=2&sender=XXXXXX');

}


而不是這個


$next_service_date_chk =$posted_data['next_service_date_chk'];


查看完整回答
反對 回復 2023-06-18
  • 1 回答
  • 0 關注
  • 133 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號