簡體   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