简体   繁体   English

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

[英]CodeIgniter: form action in nested view

I have a little problem with codeigniter and form. 我在codeigniter和表格方面有一些问题。

I'm, working on a project, where security is very important. 我正在一个项目中,安全性非常重要。 I use codeigniter and bootstrap. 我使用codeigniter和bootstrap。 I have main view, which includes navbar and some other html. 我有主视图,其中包括导航栏和其他一些html。 In that main view i have <div id="change"> which i am changing via button group. 在该主视图中,我有<div id="change"> ,我正在通过按钮组进行更改。 With those buttons I am calling functions in controller which contains $this->load->view('pages/something', $data); 使用这些按钮,我在包含$this->load->view('pages/something', $data);控制器中调用函数$this->load->view('pages/something', $data); When i press on one of those buttons <div id="change"> is changed and in it, a view, is shown and link is not changed, so main view remains as it is. 当我按下其中一个按钮时, <div id="change">被更改,并在其中显示一个视图,并且链接未更改,因此主视图保持原样。 But when one of those buttons is pressed, view with form is shown. 但是,当按下这些按钮之一时,将显示带有表单的视图。 In it i use form_open('controller/function', $attributes); 我在其中使用form_open('controller/function', $attributes); . Problem is, that when i submit this form, link is changed and main view is not on screen anymore. 问题是,当我提交此表单时,链接已更改并且主视图不再显示在屏幕上。

How can i achieve, that when i will submit form, all that will be changed is just <div id="change"> and not whole site. 我该如何实现,当我提交表单时,所有要更改的只是<div id="change">而不是整个网站。

I know i am bad in English, sorry. 我知道我英文不好,对不起。 I appreciate any help. 感谢您的帮助。 Thanks! 谢谢!

You want to refresh PART of the page and not the WHOLE page ? 您要刷新页面的一部分而不是刷新整个页面? Maybe you need AJAX. 也许您需要AJAX。

also, to make the link not changed, you have to change 另外,要使链接保持不变,您必须进行更改

config/routes.php

like this : 像这样 :

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

read this . 阅读

Hope it helps 希望能帮助到你

You can submit the form with AJAX, here's a basic example with jQuery: 您可以使用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).
});

Example modified from this answer . 从此答案修改示例。

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

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