Noah Goodrich
Noah Goodrich

Reputation: 315

Form refuses to submit in Codeigniter

Ok i'm going nuts about this issue, I can't get this form to submit, it just refreshes the page.

I've coded it exactly the same as other forms on my site, which work fine. I can't understand why it's not submitting!

Here's the controller:

public function edit($id)
        {
            // check for login, if logged in
            if($this->session->userdata('logged_in') == "1")
                {
                // Check usertype, if not correct, redirect
                if($this->session->userdata('usertype') == "0" || $this->session->userdata('usertype') == "1" || $this->session->userdata('usertype') == "2")
                    {
                        // if no photos are selected, redirect and show notification
                        $this->session->set_flashdata('notification_fail', '<p style="text-align:center; color:#fbfbfb;">You do not have permission to access that page!<p>');
                        redirect('/');
                    }
                else 
                    {
                        // get the copy details
                        $data['copy_details'] = $this->quickcopy_model->get_copy_details($id);


                        if ($_POST)
                            {
                                // get data from the submitted form
                                $title = $this->input->post('title', TRUE);
                                $copy = $this->input->post('copy', TRUE);

                                // update the row in the db
                                $this->quickcopy_model->edit_go($id, $title, $copy);

                                // redirect and show notification
                                $this->session->set_flashdata('notification', '<p style="text-align:center; color:#fbfbfb;">That copy was updated!<p>');
                                redirect('quick-copy');
                                die;
                            }

                        // load views
                        $this->load->view('templates/header', $data);
                        $this->load->view('quickcopy/quickcopy_edit', $data);
                        $this->load->view('templates/footer', $data);
                    }
                }
            else
                {
                    // redirect to signin page if not logged in
                    redirect('signin');
                }
        }

And the function being called from the model:

public function edit_go($id, $title, $copy)
        {
            $data = array(
                   'title' => $title,
                   'copy' => $copy
                );

            $this->db->where('id', $id);
            return $this->db->update('quickcopy', $data); 
        }

And finally the view:

<? echo form_open('quickcopy/edit/'.$copy_details->id); ?>
<p>Title/tagline:</p>
<input type="text" class="Form_Input" id="title" name="title" value="<? echo $copy_details->title; ?>" />

<p style="margin-top: 10px;">Copy:</p>
<textarea id="copy" name="copy" class="Form_Textarea" style="width: 970px"><? echo $copy_details->title; ?></textarea>


<button type="submit" class="Form_SubmitButton"><p style="color: #f7f7f7; text-align: center;">Save changes</p></button>
</form>

I realise i've not done form validation on this, but I have another form where I have used form validation and it won't work either!

Been totally confused about this for 2 days now, I don't get why it's not submitting. The code all looks fine to me, what other reason could there be for a form to not submit? I just installed an SSL but I have other forms that work fine so i'm assuming it's not the SSL.

Any help is most appreciated :)

Upvotes: 1

Views: 715

Answers (1)

Noah Goodrich
Noah Goodrich

Reputation: 315

OK i've managed to figure out what the issue was...at last!

Basically I have some sections of the site protected by SSL and others are not. I forgot to add the new form sections into the SSL in the htaccess file.

Working now.

Upvotes: 1

Related Questions