如何选中Conatct 7 WP中的复选框

问题描述 投票:0回答:1

我是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' );

php html wordpress contact-form-7
1个回答
0
投票

请尝试执行此操作,因为如果您的复选框为空,则不会设置该复选框。您正在执行的操作是定义是否有值。

$next_service_date_chk = isset($posted_data['next_service_date_chk']) ? true : false;

代替此

$next_service_date_chk =$posted_data['next_service_date_chk'];
© www.soinside.com 2019 - 2024. All rights reserved.