tags:

views:

36

answers:

1

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');       
    $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).

A: 

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.

bschaeffer
This works! I'd like it to work with ajax...does that mean that I'll have to write a function for this silly thing?! I'd like to keep it under the index function if I can. Any ideas?
Kevin Brown
I keep all of my ajax functionality in a model and make the ajax request to an ajax controller (either `/ajax` with method as a post parameter or `/ajax/method`). It's easier to keep the code clean and all that.... But, yes you can.
bschaeffer