2010-05-07 34 views
1

我被困在寫一個簡單的表單......我覺得愚蠢。Codeigniter:簡單的表單功能

這裏是我的控制器:

function welcome_message(){ 
    //Update welcome message 
    $id = $this->session->userdata('id');  
    $profile['welcome_message'] = $this->input->post('welcome_message'); 
    $this->db->update('be_user_profiles',$profile, array('user_id' => $id)); 
} 

和HTML:

<?php print form_open('home/welcome_message')?> 
    <input type="checkbox" value="0" checked="false">Don't show me this again</input> 
    <p> 
     <input class="button submit" type="submit" class="close-box" value="Close" /> 
    </p> 

<?php print form_close()?> 

編輯 我只是需要它提交給一個私人的功能,並返回到主頁(頁面提交)。

+1

究竟發生了什麼?什麼是錯誤? – bschaeffer 2010-05-07 19:11:49

+0

對不起,我太倉促了。我的編輯有幫助嗎? – 2010-05-07 19:15:27

+0

......編輯的答案有意義嗎? – bschaeffer 2010-05-07 19:22:00

回答

0

您必須爲您的輸入命名...?

<input type="checkbox" value="0" name="welcome_message" checked="false"> 
    Don't show me this again 
</input> 

編輯:無法通過URL提交給私有函數(在默認安裝CI,反正)。

做這樣的:

function welcome_message() 
{ 
    if(isset($_POST['welcome_message'])) 
    { 
     $this->_my_private_function(); 
    } 
} 

private function _my_private_function() 
{ 
    // do your thing with the $_POST data 

    redirect('your/uri', 'location'); 
} 

但是,你真的沒有,如果你的迴歸到同一個頁面(控制器方法)稱爲擺在首位的私有函數重定向。會是一種浪費。

+0

這個工程!我希望它能與ajax一起工作......這是否意味着我必須爲這個愚蠢的東西寫一個函數?!如果可以的話,我想保留在索引函數下。有任何想法嗎? – 2010-05-07 19:31:48

+0

我將所有的ajax功能都保存在模型中,並將ajax請求發送到ajax控制器('/ ajax',方法爲post參數或'/ ajax/method')。保持代碼清潔和所有這些更容易....但是,是的,你可以。 – bschaeffer 2010-05-07 19:35:23