1

这是我的一个表格。我想将表单条目发布到同一页面,然后用它做其他事情。但是,呼应这些值似乎不起作用。我究竟做错了什么?

这是 HTML 部分:

<div class="well">
        <form name="myform" class="form-horizontal" id="form" onsubmit="return validateForm(this);" action="my.php" method="post">
                <div class="control-group input-append">
                <label for="text" class="control-label">Field1</label>
                    <div class="controls">
                        <div class="left">
                                <input id="Field1" name="Field1" type="text"/> 
                             </div>
                    </div>
             </div>
                 <br>
             <div class="control-group input-append">
                <label for="passwd" class="control-label">Field2</label>
                    <div class="controls">
                        <div class="left1">
                                <input id="Field2" name="Field2" type="password" /> 
                        </div>
                    </div>
                </div>
                <br>
            <div class="control-group input-append">
                <label for="passwd" class="control-label">Field3</label>
                    <div class="controls">
                        <div class="left1">
                                <input id="Field3" name="Field3" type="password"/> 
                        </div>
                    </div>
            </div>
            <br>
            <div class="control-group input-append">
                <label for="select" class="control-label">Field4</label>
                    <div class="controls">
                        <div class="left1">
                            <select class="form-control" name="Field4">
                                 <option value="OP1">OP1</option>
                                 <option value="OP2">OP2</option>
                                 <option value="OP3">OP3</option>
                                 <option value="OP4">OP4</option>
                            </select>
                        </div>

                    </div>
            </div>
            <br>
            <div class="control-group input-append">
                <label for="text" class="control-label">Field5</label>
                    <div class="controls">
                        <div class="left">
                            <input type="Field5" id="Field5" name="type"/> 
                        </div>
                    </div>
            </div>
            <br>
                <div class="control-group input-append">
                <label for="text" class="control-label">Field6</label>
                    <div class="controls">
                        <div class="left">
                            <input type="text" id="Field6" name="Field6"/> 
                        </div>
                    </div>
            </div>
                <br>
            <div class="control-group">
                <div class="controls">
                    <div class="left1">
                        <input type="submit" class="btn btn-success"/>
                     </div>
                </div>
                </div>
        </form>
    </div>

PHP部分:

<?php
if (isset($_POST['submit'])) 
{ 
  echo $_POST['name'];
 } else {?>
<?php;}?>
4

4 回答 4

1

没有带有 name 的字段$_POST['name'],尽管您有带有编号名称的字段,例如$_POST['Fields3']

要调试表单请求,首先打印出整个$_POST数组:

var_dump( $_POST );

输入的type和它的不一样name

于 2013-09-26T07:42:07.123 回答
1

另一种选择是更换

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

和:

if($_SERVER['REQUEST_METHOD'] == 'POST')
于 2013-09-26T07:49:47.387 回答
0

替换 <input type="submit" class="btn btn-success"/>

<input type="submit" name="submit" class="btn btn-success"/>

于 2013-09-26T07:42:19.973 回答
0

问题在这里:

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

您的提交按钮

<input type="submit" class="btn btn-success" />

没有value,也没有name。Post 使用以下属性:

$_POST['<name>'] = <value>

将您的输入更改为

<input type="submit" name="submit" value="Submit" class="btn btn-success" />

顺便说一句,很高兴看到人们仍在使用 XHTML 进行编码。如果您使用的是 HTML 5,则不应以斜杠结束非结束标签... />

于 2013-09-26T07:46:11.230 回答