【发布时间】: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。
非常感谢任何帮助:)
【问题讨论】:
-
这
<? echo form_open('quickcopy/edit/'.$copy_details->id); ?>行是否返回$copy_details->id中所需的ID? -
你确定你的表单验证如下:
if ($this->form_validation->run() == FALSE) { $this->load->view('myform'); } else { $this->load->view('formsuccess'); } -
@Vlakarados - 是的,它得到了正确的 ID。
-
@Jamshid Hashimi - 我已经在另一个同样不起作用的表单上完成了类似的表单验证。我不知道为什么。
-
@NoahGoodrich 您是否尝试过删除用户登录和用户类型部分以查看它是否可以在没有它的情况下工作?
标签: php forms codeigniter