操作取决于单选按钮输入

时间:2016-11-23 10:54:59

标签: php html

我有这个项目:"custom_fields"=> [["actief_in_duitsland"=>1]]

在这个数组中:

$sales_payload = array(
    'organization_id' => $organization_id,
    'contact_id' => $contact_id,
    'status' => 'Open',
    'subject' => $_product->post_title." ".str_replace($strToRemove, "", $_POST['billing_myfield12']),
    'start_date' => date("Y-m-d"), // set start date on today
    'expected_closing_date' => date("Y-m-d",strtotime(date("Y-m-d")."+ 14 days")), // set expected closing date 2 weeks from now
    'chance_to_score' => '10%',
    'expected_revenue' => 0, //set the expected revenue
    'note' => $_POST['order_comments'],

    'progress' => array(
    'id'=>'salesprogress:200a53bf6d2bbbfe' //fill a valid salesprogress id to set proper sales progress 
    ),

    "custom_fields"=> [["actief_in_duitsland"=>1]]
);

我有2个单选按钮:

<div class="form-row form-row-wide " id="billing_myfield13_field">
        <fieldset><legend>Bent u actief in Duitsland?</legend>
        <label><input type="radio"  checked='checked' name="billing_myfield13" value="Ja"/> Ja</label>
        <label><input type="radio"  name="billing_myfield13" value="nee" /> nee</label>
        </fieldset>
        </div>

现在我想要实现的是当单选按钮包含&#39; ja&#39;检查此数组中的值应为1

"custom_fields"=> [["actief_in_duitsland"=>1]]

其他或价值&#39; nee&#39;:

"custom_fields"=> [["actief_in_duitsland"=>0]]

我一直在寻找,我无法找到具体的答案。我可以得到一个例子或类似的东西,将我引向正确的方向。

提前致谢,

凯文

1 个答案:

答案 0 :(得分:1)

也许

<?php 
if(!empty($_POST['billing_myfield13']) && $_POST['billing_myfield13'] ==='ja') {
   $value = 1;
}else{
   $value = 0;
}

$sales_payload = array(
    'organization_id' => $organization_id,
    'contact_id' => $contact_id,
    'status' => 'Open',
    'subject' => $_product->post_title." ".str_replace($strToRemove, "", $_POST['billing_myfield12']),
    'start_date' => date("Y-m-d"), // set start date on today
    'expected_closing_date' => date("Y-m-d",strtotime(date("Y-m-d")."+ 14 days")), // set expected closing date 2 weeks from now
    'chance_to_score' => '10%',
    'expected_revenue' => 0, //set the expected revenue
    'note' => $_POST['order_comments'],

    'progress' => array(
    'id'=>'salesprogress:200a53bf6d2bbbfe' //fill a valid salesprogress id to set proper sales progress 
    ),

    "custom_fields"=> [["actief_in_duitsland"=> $value]]
);