CodeIgniter的表单操作无法正常工作

编程入门 行业动态 更新时间:2024-10-25 08:19:13
本文介绍了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的表单操作无法正常工作

本文发布于:2023-10-12 16:39:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1485285.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表单   无法正常   操作   工作   CodeIgniter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!