开发者

Codeigniter: simple form function

开发者 https://www.devze.com 2022-12-30 01:49 出处:网络
I\'m stuck writing a simple form...I feel dumb. Here\'s my controller: function welcome_message(){ //Update welcome message

I'm stuck writing a simple form...I feel dumb.

Here's my controller:

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

And the 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()?>

Edit I simply need it to submit to a private function and return to the home page (page submitted from).


You have to name your input...?

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

EDIT: You can't submit to a private function via the URL (in a default CI installation, anyway).

Do it like this:

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');
}

But you really don't have to redirect if your returning to the same page (controller method) that called the private function in the first place. Would be a waste.

0

精彩评论

暂无评论...
验证码 换一张
取 消