【问题标题】:codeigniter - form submission mistakecodeigniter - 表单提交错误
【发布时间】:2014-01-07 12:07:33
【问题描述】:

我为这项工作制作了一个普通表格,供用户以表格形式提交数据名称、电子邮件和城市,我使用了一些编码,但我仍然不知道我在哪里弄错了请提出建议。

路线

$route['default_controller'] = "welcome";

控制器中的welcome.php

public function index()
    {
        $this->load->view('ar_signup');     
        $this->load->helper('url');
    }
}

视图中表单的 ar_signup

<!DOCTYPE html> 
<html lang="en-US">
  <head>
    <title>Landing Page</title>
    <meta charset="utf-8">
    <link href="assests/css/ar/ar.css" rel="stylesheet" type="text/css">
  </head>
  <body>
        <?php echo validation_errors(); ?>
        <?php echo form_open('user'); ?>
        <label for="name">Name:</label>
        <input type="name" id="name" name="name">   
        <label for="email">Email:</label>       
        <input type="email" id="email" name="email">        
        <label for="city">City:</label>     
        <input type="city" id="city" name="city">       
        <input type="submit" value="Login">     
        </div>      
        </form>     

  </body>
</html> 

控制器中的user.php

<?php
function create_member()
    {
        $this->load->library('form_validation');        

        // field name, error message, validation rules
        $this->form_validation->set_rules('name', 'Name', 'trim|required');
        $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
        $this->form_validation->set_rules('city', 'City', 'trim|required');     

        if($this->form_validation->run() == FALSE)
        {
            $this->load->view('ar_thanks');
        }
        else
        {           
            $this->load->model('users_model');

            if($query = $this->Users_model->create_member())
            {
                $this->load->view('ar_landing');            
            }

        }

    }

模型中提到的user_model.php

<?php
function create_member()
    {

        $this->db->where('user_name', $this->input->post('username'));
        $query = $this->db->get('users');

        if($query->num_rows > 0){           
        }else{
            $new_member_insert_data = array(
                'name' => $this->input->post('name'),
                'email' => $this->input->post('email'),
                'city' => $this->input->post('city'),                           
            );
            $insert = $this->db->insert('users', $new_member_insert_data);
            return $insert;
        }

    }//create_member
}

【问题讨论】:

  • 有什么问题?你有什么错误吗?
  • 你的$this-&gt;load-&gt;helper('form');在哪里?
  • 在自动加载中我添加 $autoload['helpers'] = array('form');
  • 那么问题出在哪里?
  • 当我提交表单时显示,未找到在此服务器上未找到请求的 URL /landingpage/user。

标签: php forms codeigniter


【解决方案1】:

在您的 user.php 控制器中更改

if($this->form_validation->run() == FALSE)
    {
        $this->load->view('ar_thanks');
    }

if($this->form_validation->run() == FALSE)
    {
        $this->load->view('ar_signup');
    }

在你的视图文件中给出这个:&lt;?php echo form_open('user/create_member'); ?&gt;

现在点击你的:localhost/landingpage/index.php/user/create_member

【讨论】:

  • 我已经检查过它即使在默认索引中也不起作用我测试了我已经完成的所有操作但我不明白错误在哪里。
  • &lt;?php echo form_close(); ?&gt; 而不是&lt;/form&gt;
  • 还是一样,没什么变化!
  • 你的项目 url 是什么?也将 &lt;link href="assests/css/ar/ar.css" rel="stylesheet" type="text/css"&gt; 更改为 &lt;link href="&lt;?php echo base_url();?&gt;assests/css/ar/ar.css" rel="stylesheet" type="text/css"&gt;
  • 致命错误:在 C:\wamp\www\landingpage\application\views\ar_signup.php 第 6 行调用未定义函数 base_url() 调用堆栈 #TimeMemoryFunctionLocation 10.0000152376{main}( ).. \index.php:0 20.0000188440require_once(续...
【解决方案2】:

如果您的控制器是 'welcome',那么您的 url 应该是 'localhost/welcome'。还要检查你的 mod_rewrite。 编辑

我认为这将是你的 php 安装,因为你说当你删除 php 代码时,它工作得很好。

【讨论】:

  • 已经检查您是否检查了 cmets,您还会看到我粘贴的 .httaccess 文件。
猜你喜欢
  • 2012-05-03
  • 1970-01-01
  • 1970-01-01
  • 2016-07-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-26
相关资源
最近更新 更多