【问题标题】:Form refuses to submit in Codeigniter表单拒绝在 Codeigniter 中提交
【发布时间】:2012-07-03 17:30:51
【问题描述】:

好吧,我对这个问题发疯了,我无法提交此表单,它只会刷新页面。

我已将其编码为与我网站上的其他表单完全相同,它们运行良好。我不明白为什么它不提交!

这是控制器:

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

以及从模型中调用的函数:

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

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

最后是视图:

<? 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>

我意识到我没有对此进行表单验证,但我有另一个表单,我使用了表单验证,但它也不起作用!

现在已经完全困惑了 2 天,我不明白为什么它没有提交。代码在我看来都很好,还有什么其他原因导致表单无法提交?我刚刚安装了 SSL,但我还有其他可以正常工作的表单,所以我假设它不是 SSL。

非常感谢任何帮助:)

【问题讨论】:

  • &lt;? echo form_open('quickcopy/edit/'.$copy_details-&gt;id); ?&gt; 行是否返回$copy_details-&gt;id 中所需的ID?
  • 你确定你的表单验证如下:if ($this-&gt;form_validation-&gt;run() == FALSE) { $this-&gt;load-&gt;view('myform'); } else { $this-&gt;load-&gt;view('formsuccess'); }
  • @Vlakarados - 是的,它得到了正确的 ID。
  • @Jamshid Hashimi - 我已经在另一个同样不起作用的表单上完成了类似的表单验证。我不知道为什么。
  • @NoahGoodrich 您是否尝试过删除用户登录和用户类型部分以查看它是否可以在没有它的情况下工作?

标签: php forms codeigniter


【解决方案1】:

好的,我已经设法找出问题所在……终于!

基本上,我网站的某些部分受 SSL 保护,而其他部分则没有。我忘了在 htaccess 文件的 SSL 中添加新的表单部分。

现在工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-06
    • 1970-01-01
    • 2017-09-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多