为什么我的action属性不能在下面的代码中工作

时间:2016-11-04 06:53:27

标签: php html forms

    //Here i have mentioned one form and gave action in that.I also gave a button submit.Now when I click on the submit button, It the action given in the form is not perfoming.



<form action="submit.php" method="POST">
            <tbody>
                <tr id='addr0' data-id="0" class="hidden">
                <td data-name="loannum">
                  <input type="number" class="form-control" required>
                </td>
                <td data-name="name">
                  <input id="startdate" name="startdate" min="2016-01-01" max="2020-01-01" type="date" class="form-control">
                </td>
                <td data-name="name">
                    <input type="text" name='gname' placeholder='Group Name' class="form-control"  pattern="([A-z\s]){2,}" required/>
                </td>
                <td data-name="desc">
                    <input type="number" placeholder='Batch Number' class="form-control" pattern="[0-9]{9}" required>
                </td>   
            </tr>
        </tbody>
    </table>
</div>
</div>
    <a id="add_row" class="btn btn-primary" style="background:#84ca71;color:#F44336;padding-bottom:24px;">Add Group</a>
//here we mentioned a button and when we click on it the action given in form should be performed
    <button class="btn btn-default" type="submit"  style="background:#cddc39;color:#F44336;padding:5px 30px 25px 20px;">submit</button>
    </form>

2 个答案:

答案 0 :(得分:2)

如果您确实使用了I also gave a button submit底部的按钮,还需要添加</form>结束表单标记。

另请注意,此输入将不返回任何内容:

<input type="number" class="form-control" required>

因为你没有在这里使用name属性。

您还需要为Batch Number字段添加名称属性。

<input type="number" placeholder='Batch Number' class="form-control" pattern="[0-9]{9}" required>

<强>更新

根据您的意见,您正在使用按钮和结束表单标记,这意味着,这是与表单操作无关的纯PHP问题。

你需要什么:

  • 您必须检查相同根目录下的submit.php是否可用,或者只有一个文件而不是空白<form action="">

  • 在submit.php文件中,您还需要检查帖子值,例如print_r($_POST),检查您获得的内容并添加缺少的名称属性。

  • 最重要的部分是,不知道您是否使用isset(),如何使用此输入检查提交按钮是否设置: <button class="btn btn-default" type="submit" style="background:#cddc39;color:#F44336;padding:5px 30px 25px 20px;">

答案 1 :(得分:0)

下面是正常工作的代码。 form.html

<!DOCTYPE html>
<html>
<head>
<title>Popup Timepicker Demo Using AngularJS, Bootstrap</title>

<meta name="viewport" content="width=device-width, initial-scale=1">

<meta charset="UTF-8">
<meta name="description"
    content="Popup Timepicker Demo Using AngularJS, Bootstrap.">

</head>
<body>
 <form action="submit.php" method="POST">
        <tbody>
            <tr id='addr0' data-id="0" class="hidden">
            <td data-name="loannum">
              <input type="number" name="name1" class="form-control" required>
            </td>
            <td data-name="name">
              <input id="startdate" name="startdate" min="2016-01-01" max="2020-01-01" type="date" class="form-control">
            </td>
            <td data-name="name">
                <input type="text" name='gname' placeholder='Group Name' class="form-control"  pattern="([A-z\s]){2,}" required/>
            </td>
            <td data-name="desc">
                <input type="number" name="name2" placeholder='Batch Number' class="form-control" pattern="[0-9]{9}" required>
            </td>   
        </tr>
    </tbody>
</table>
    </div> </div> <a id="add_row" class="btn btn-primary" style="background:#84ca71;color:#F44336;padding-bottom:24px;‌​">Add Group</a> <button class="btn btn-default" type="submit" style="background:#cddc39;color:#F44336;padding:5px 30px 25px 20px;">submit</button> </form>
</body>
</html>

下面是submit.php代码,该代码与form.html的文件夹相同。

print_r($_POST);