如何使单选按钮返回布尔值真/假而不是开/关

2022-01-21 00:00:00 arrays radio-button php

我希望我的单选按钮返回一个布尔值 true 或 false instade of on/off

I want that my radio buttons return me a Boolean value true or false instade of on/off

所以我在输入值中传递真/假:

So I pass the true/false in the value of the input :

<label>Male
   <input type="radio" name="IsMale" value="true" />
</label> 
<label>Female
   <input type="radio" name="IsMale" value="false" />
</label>

但它以文本格式返回真/假.请高手,我怎样才能以布尔格式获得它们?

but it returns me a true/false in a text format. Please masters how could I get them in a booleen format ?

更多细节:事实上,我需要将我的 $_POST 数组存储在 file.txt 中,例如,对于我的单选按钮,我需要存储:

More details : In fact I need to store my $_POST array in a file.txt, and for my radio button I need to store for example :

array ( "IsMale" => true );

而不是:

array ( "IsMale" => "true" );

推荐答案

你必须检查数据并修改它.

You'll have to check the data and modify it.

if(isset($_POST['SubmitButton'])) { 

  $_POST['IsMale'] = $_POST['IsMale'] == 'true' ? true : false;
}

相关文章