Kevin.a Kevin.a - 13 days ago 4
PHP Question

Action depending on radio button input

I have this item:

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


inside this array :

$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]]
);


And i have 2 radio buttons:

<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>


Now what i want to achieve is when the radio button containing 'ja' is checked the value in this array should be 1

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


else or the value 'nee':

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


I have been looking everywhere and i couldnt find a specific answer. Could i get an example or like something that would lead me to the right direction.

Thanks in advance,

Kevin

Answer

Maybe

<?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]]
);