How to make a radio button return boolean true/false instead of on/off(如何使单选按钮返回布尔值真/假而不是开/关)
问题描述
我希望我的单选按钮返回一个布尔值 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;
}
这篇关于如何使单选按钮返回布尔值真/假而不是开/关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使单选按钮返回布尔值真/假而不是开/关


基础教程推荐
- 将变量从树枝传递给 js 2022-01-01
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- php中的PDF导出 2022-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
- Web 服务器如何处理请求? 2021-01-01
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- php中的foreach复选框POST 2021-01-01