CodeIgniter的表单操作无法正常工作 [英] CodeIgniter's form action is not working properly

查看:142
本文介绍了CodeIgniter的表单操作无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我失败了很多次,以了解为什么我的表单的action属性在我点击提交按钮时出现故障。

I have failed many times to figure out why the action attribute of my form is malfunctioning when I click the submit button.

我只想将表单数据传递给控制器​​。但是发生了什么,浏览器只是将我重定向到另一个页面(在localhost,即使是正确提供的URI。)

All I wanted to do is to pass the form data to the controller. But what's happening is that the browser is just redirecting me to another page (on localhost, even the URI is correctly supplied.)

<form name = "employee" method = "post" action = "<?php echo base_url() .'employee/add_employee'; ?>">
First Name:  <input type = "text" name = "F_Name">
Middle Name: <input type = "text" name = "M_Name">
Last Name:   <input type = "text" name = "L_Name">
<input type = "submit" value = "save">
</form>

这里是我的employee.php中的add_employee函数(类名为'Employee' / p>

Here's the add_employee function in my employee.php (with the class name of 'Employee'):

public function add_employee(){

    $employee = array(
    'F_Name' => $this->input->post('F_Name'),
    'M_Name' => $this->input->post('M_Name'),
    'L_Name' => $this->input->post('L_Name')
    );

    $this->Employee_model->insert_employee($employee);

    echo "Employee added!<br />";
}



我不认为Employee_model是问题,所以我不会在这里添加。我猜这个问题与我的表单操作中的URL有关。

I don't think the Employee_model is the problem, so I won't add it here. I'm guessing that the problem has to do with the URL in my form action.

为什么浏览器将我重定向到另一个页面而不是执行add_employee()函数?

Why is the browser redirecting me to another page instead of executing the add_employee() function?

推荐答案

经过长时间的讨论,以下是解决方案:

So after a long discussion, here is the solution :

在您的htaccess中,您必须更改

In your htaccess, you had to change

将RewriteBase / CI / 转换为 RewriteBase / CI_Practice2

此外,也许你必须用MAMP(也许不能)这样做。

Also, maybe you have to do this with MAMP (Maybe not)

localhost:8080 / CI_Practice2

localhost:8080/CI_Practice2

这是如果你没有更改MAMP的默认端口。

It's if you didn't change the defaults ports of MAMP.

有一个愉快的一天

这篇关于CodeIgniter的表单操作无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆