Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/91.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用$\u POST发送无线信箱值_Php_Html_Forms_Post_Radio Button - Fatal编程技术网

Php 使用$\u POST发送无线信箱值

Php 使用$\u POST发送无线信箱值,php,html,forms,post,radio-button,Php,Html,Forms,Post,Radio Button,即使字段为空,如何向$\u POST数组发送radio或checkbox值 <?php if(isset($_POST)) { echo '<pre>'; print_r($_POST); echo '</pre>'; } ?> <form action="test.php" method="POST"> <input type="text" name="name"&g

即使字段为空,如何向$\u POST数组发送radio或checkbox值

<?php
    if(isset($_POST)) {
        echo '<pre>';
        print_r($_POST);
        echo '</pre>';
    }
?>

<form action="test.php" method="POST">
    <input type="text" name="name">
    <input type="text" name="email">
    <input type="radio" name="gender">

    <input type="submit"> 
</form>
<form action="test.php" method="POST">

<input type="text" name="name">
<input type="text" name="email">
<input type="radio" name="gender" value='' checked>

<input type="submit"> 
</form>
如您所见,在不接触输入类型文本的情况下,它们的值被推送到$\u POST数组中。我怎样才能用收音机盒做到这一点?我基本上想“设置”它,尽管它和文本输入一样是空白的

我知道我随时都可以打电话

<form action="test.php" method="POST">
    <input type="text" name="name">
    <input type="text" name="email">
    <input type="radio" name="gender" value="male"/>Test
    <input type="submit" name="submit" value="submit"/>
</form>

但这不一定是我想要的。我需要它自动设置。提前谢谢

应该是:

HTML:

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

    echo $radio_value = $_POST["radio"];
}

试试这个,它会起作用的:

未选中的无线电
元素未提交,因为它们未被视为
成功
。因此,您必须检查它们是否使用
isset
empty
功能发送


男性

如果要自动发送空白值,则
默认情况下,选中该单选按钮并设置空白值:

Array
(
    [name] => 
    [email] => 
    [gender]=>male
)

考虑以下示例:

HTML :
<form action="test.php" method="POST">
<input type="text" name="name">
<input type="text" name="email">
<input type="radio" name="gender" checked  value="male"/>Male
<input type="radio" name="gender" value="female"/>Female
<input type="submit" name="submit" value="submit"/>
</form>

PHP :
 if(isset($_POST)) {
    echo '<pre>';
    print_r($_POST);
    echo '</pre>';
}
您只会在
$\u POST
数组中选中
收音机

HTML:
男性
女性
PHP:
国际单项体育联合会(国际单项体育联合会){
回声';
Array
(
    [name] => 
    [email] => 
)
// Set a default value as male
<input type="radio" name="gender" checked value="male"> Male
<input type="radio" name="gender" value="femail"> Female
打印(邮政美元); 回声';
Array
(
    [name] => 
    [email] => 
)
// Set a default value as male
<input type="radio" name="gender" checked value="male"> Male
<input type="radio" name="gender" value="femail"> Female
}

男性
女性

Hmm,看起来它只是将“提交”项添加到了$\u POST数组中。我得到的结果是`数组([name]=>[email]=>[submit]=>submit)`@xToxikx,你只会在
$\u POST
数组中得到
选中的
收音机的值。我编辑了我的答案。我希望这会对你有所帮助。啊,好吧,明白了,我试图避免这种情况,因为我不想假设用户是特定性别的,但看起来这可能是唯一的选择。谢谢是的,我之前确实调查过这件事,并且成功了。这是一种选择,唯一的问题是我们假设用户自动为“男性”或“女性”。这只是一种美学上的东西,但也许我不得不做出牺牲。谢谢@xToxikx,如果未选中
$\u POST
数组中的
属性,则无法获取单选按钮值。
<form action="" method="POST">
<input type="text" name="name">
<input type="text" name="email">
<input type="radio" name="gender" checked value="male"> Male
<input type="radio" name="gender" value="femail"> Female
<input type="submit" value="submit"> 
</form>

<?php
if(isset($_POST)) {
    echo '<pre>';
    print_r($_POST);
    echo '</pre>';
}
?>