【问题标题】:Submit Button Only Working on Index Page提交按钮仅适用于索引页面
【发布时间】:2016-05-14 00:29:30
【问题描述】:

在网站的任何页面上,除了索引页面(它应该正常工作)时,表单没有向页面提交数据(更改密码)时遇到问题。该网站是使用 CodeIgniter 构建的。

目前在所有页面上使用的表单代码如下:

<div class="modal-body">
    <form role="form" id="change_password_form" action="<?php echo base_url('auth/change_password')?>" method="post">
        <fieldset>
            <div class="form-group">
                <input class="form-control" placeholder="Old Password" name="old" type="password" autofocus>
            </div>
            <div class="alert alert-danger" id="old" role="alert" style="display:none"></div>
            <div class="form-group">
                <input class="form-control" placeholder="New Password - minimum 8 characters" name="new" type="password" value="">
            </div>
            <div class="alert alert-danger" id="new" role="alert" style="display:none"></div>
            <div class="form-group">
                <input class="form-control" placeholder="Confirm New Password" name="new_confirm" type="password" value="">
            </div>
            <div class="alert alert-danger" id="new_confirm" role="alert" style="display:none"></div>
            <input type="hidden" name="user_id" value="<?php echo $user_id;?>" id="user_id"  />
        </fieldset>
</div>
<div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary" id="changepassword" value="Submit">Submit</button>
    </form>
</div>

在索引页面上,这成功进入change_password函数,并会检查详细信息是否符合规则。单击提交时,文本框下方会显示一条错误消息。但是在使用相同代码的其他页面上,单击提交时没有任何反应。当我进入 Main.php 并将 index 函数中 index.php 的页面更改为任何其他页面(例如 view_inventory.php)时,更改密码在新索引页面上正常工作,但在旧索引上不起作用页面。

如果我用下面的代码替换提交按钮,我可以获得更改密码以在其他页面上工作(不会在文本框下显示结果,而是在新的空白页面上),但我真的没有如果可以修复的数量较少,希望不得不编辑这么多页面。

<input type="submit" value="Submit" class="btn btn-primary">

任何帮助将不胜感激。

【问题讨论】:

  • 你需要这样做,这样做更容易

标签: php html forms codeigniter submit


【解决方案1】:

上周我遇到了同样的错误。您必须使用提交内部表单而不是按钮。

您可以使用form_submit 例如:

echo form_submit('mysubmit', 'Submit');
// Would produce:  <input type="submit" name="mysubmit" value="Submit" />

这是文档:

http://www.codeigniter.com/user_guide/helpers/form_helper.html

问候。

【讨论】:

  • 啊,所以必须使用 而不是
  • 是的,我必须在
    内。
  • 感谢您的帮助!看起来我必须进行比我想要的更多的编辑才能获得相同的布局,但至少主要部分(Channing Passwords)在所有页面上都可以正常工作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-25
  • 1970-01-01
  • 1970-01-01
  • 2013-07-16
  • 1970-01-01
相关资源
最近更新 更多