如何使单选按钮返回布尔值true/false,而不是on/off [英] How to make a radio button return boolean true/false instead of on/off
本文介绍了如何使单选按钮返回布尔值true/false,而不是on/off的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望我的单选按钮向我返回一个布尔值,表示对开/关的正确或错误
I want that my radio buttons return me a Boolean value true or false instade of on/off
因此,我在输入值中传递了true/false:
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>
但是它以文本格式返回真/假.请高手,我怎样才能把它们做成booleen格式?
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;
}
这篇关于如何使单选按钮返回布尔值true/false,而不是on/off的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文