繁体   English   中英

CodeIgniter:嵌套视图中的表单操作

[英]CodeIgniter: form action in nested view

我在codeigniter和表格方面有一些问题。

我正在一个项目中,安全性非常重要。 我使用codeigniter和bootstrap。 我有主视图,其中包括导航栏和其他一些html。 在该主视图中,我有<div id="change"> ,我正在通过按钮组进行更改。 使用这些按钮,我在包含$this->load->view('pages/something', $data);控制器中调用函数$this->load->view('pages/something', $data); 当我按下其中一个按钮时, <div id="change">被更改,并在其中显示一个视图,并且链接未更改,因此主视图保持原样。 但是,当按下这些按钮之一时,将显示带有表单的视图。 我在其中使用form_open('controller/function', $attributes); 问题是,当我提交此表单时,链接已更改并且主视图不再显示在屏幕上。

我该如何实现,当我提交表单时,所有要更改的只是<div id="change">而不是整个网站。

我知道我英文不好,对不起。 感谢您的帮助。 谢谢!

您要刷新页面的一部分而不是刷新整个页面? 也许您需要AJAX。

另外,要使链接保持不变,您必须进行更改

config/routes.php

像这样 :

$routes['controller/method'] = "your link";

阅读

希望能帮助到你

您可以使用AJAX提交表单,这是jQuery的基本示例:

// this is the id of the form
$("#idForm").submit(function() {

    var url = "path/to/your/script"; // the script where you handle the form input.

    $.ajax({
        type: "POST",
        url: url,
        data: $("#idForm").serialize(), // serializes the form's elements.
        success: function(data) {
             // 'data' is the response from the php script.
             // Update <div id="change"> here.
        }
    });

    return false; // avoid to execute the actual submit of the form. (This stops the URL changing).
});

从此答案修改示例。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM