【问题标题】:why my action attribute is not working in the below code为什么我的动作属性在下面的代码中不起作用
【发布时间】:2017-03-17 22:44:39
【问题描述】:
    //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>

【问题讨论】:

  • 你的按钮在哪里?
  • 你忘记添加按钮和&lt;/form&gt;
  • offo 我忘了链接那个代码。所以这里是按钮代码。
    添加组

标签: php html forms


【解决方案1】:

如果你真的使用底部I also gave a button submit的按钮,还需要添加&lt;/form&gt;关闭表单标签。

还要注意,这个输入不会返回任何内容:

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

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

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

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

更新:

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

你需要什么:

  • 您必须检查submit.php 在同一根目录下是否可用,或者如果您只有一个文件而不是将其留空&lt;form action=""&gt;

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

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

【讨论】:

  • 即使我添加了 name 属性并在 submit.php 中提到了 print_r($_POST) 但我没有得到输出
  • @BhargaviK:分享 submit.php 文件
  • 我只给出了这个,因为我只需要在点击提交时重定向页面。
  • 整个源代码来自 submit.php &lt;?php print_r($_POST); ?&gt;
  • 是的,因为我只是想检查我的按钮是否工作
【解决方案2】:

下面是运行良好的代码。 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>

下面是form.html文件夹下的submit.php代码

print_r($_POST);

【讨论】:

  • 你能告诉我你遇到什么样的问题我可以帮助你
  • 复制上面所有form.html的代码,然后提交表单
  • 你得到的是空白数组吗?
  • 上面的代码在我的电脑上工作正常,也许是发布数据的 php 问题。请尝试 method="get" 和 php 端 并检查它是否工作
猜你喜欢
  • 1970-01-01
  • 2018-12-15
  • 2017-06-15
  • 1970-01-01
  • 1970-01-01
  • 2016-03-21
  • 1970-01-01
  • 2014-01-23
  • 2013-08-06
相关资源
最近更新 更多