代码点火器表单提交


Codeigniter form submission

所以我对Codeigniter相当陌生...我的本地主机上有一个提交表单的文件:

 $id =array('id' => 'commentForm');
 echo form_open("form_validate", $id);
public function form_validate()
{
    $this->load->library("form_validation");
    $this->form_validation->set_rules('date', 'Date', 'required');
    $this->form_validation->set_rules('Cname', 'Client Name', 'required');
 ....
  }

据我了解,当我在表单上点击提交时,它会转到控制器中的函数"form_validate()"(或您在提交页面上设置的任何内容)并执行它。

该代码在我的本地主机上运行良好,但是一旦我将其上传到我的实时服务器,它就不会转到控制器中的函数,而是查找一个名为 form_validation 的页面(至少这是我从 URL 中想到的)

我已将基本路径重写为:

    $config['base_url'] = 'http://mysite.com/ci_form';

并摆脱了索引.php在索引下我还采用了Codeigniter mod_rewrite从他们的网站

 <IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ci_form/
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.

#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

 <IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php

你在form_open("form_validate");函数中缺少你的控制器,这就是为什么它正在寻找一个名为form_validate的控制器。

它需要form_open("your_controller_name/form_validate");

http://ellislab.com/codeigniter/user-guide/helpers/form_helper.html

此外,您的表单应该在您的视图中

也许这会有所帮助