【问题标题】:Codeigniter form submissionCodeigniter 表单提交
【发布时间】:2013-01-25 20:19:57
【问题描述】:

所以我对 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';

并且去掉了index下的index.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

【问题讨论】:

    标签: php codeigniter


    【解决方案1】:

    form_open("form_validate"); 函数中缺少控制器,这就是它寻找名为 form_validate 的控制器的原因。

    必须是form_open("your_controller_name/form_validate");

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

    您的表单也应该在您的视图中

    也许this 会有所帮助

    【讨论】:

      猜你喜欢
      • 2012-09-03
      • 2011-02-24
      • 2017-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-08
      相关资源
      最近更新 更多