【问题标题】:CodeIgniter showing correct URL if validation error occurred in edit form如果编辑表单中发生验证错误,CodeIgniter 会显示正确的 URL
【发布时间】:2015-12-18 17:06:41
【问题描述】:

我有一个带有编辑方法的控制器和我的编辑 URL,例如

http://localhost/pothdekhun/road/edit/3

当发生任何服务器端错误时,使用以下代码我会显示相同的错误表单

if ($this->form_validation->run() == FALSE) {
   //this is loading edit view form
   $this->nuts_lib->view_loader('user', 'add', $data, TRUE, 'latest_routes', 'rightbar');
   return;
}

现在我的问题出在 URL 中,URL 显示为(当编辑表单出错时)

http://localhost/pothdekhun/road/edit

据我们所知,此处无法使用验证错误消息进行重定向。现在我该如何解决这个问题?

所以我想要像 http://localhost/pothdekhun/road/edit/3 这样带有验证消息的 URL。我会像 site_url('road/edit/').$route_id 这样更改我的编辑表单操作还是有更好的主意??

【问题讨论】:

  • 你的表单atction是同一个页面吗?
  • 要做到这一点,我认为您需要将表单操作设置为同一页面,就像您在问题中所说的那样 site_url('road/edit/').$route_id
  • 我提到的方式有问题。隐藏字段的值在视图页面中丢失
  • 您可能在 $_REQUEST 数组中有隐藏字段值,尝试通过检查 isset($_REQUEST['field_name'])?$_REQUEST['field_name']:"" 来更新值以隐藏输入
  • 对于隐藏字段,请在此处查看我的答案stackoverflow.com/questions/34319727/…

标签: php codeigniter


【解决方案1】:

根据讨论,您遇到的问题是提交表单上的隐藏字段缺少值以及是否存在表单错误。请按照我的回答来获取表单提交后的值。 How to prevent forms from emptying inputs by submiting the form in html?

【讨论】:

    猜你喜欢
    • 2016-05-11
    • 1970-01-01
    • 2014-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-14
    • 1970-01-01
    相关资源
    最近更新 更多