chinesebear 发表于 2013-4-5 21:13:32

form的action问题,url被追加了(已解决)

本帖最后由 chinesebear 于 2013-4-6 09:31 编辑

教程里的例子
http://localhost/ci/index.php/news/create
给数据库添加一条记录,点击确定之后,url为:http://localhost/ci/index.php/news/ci/index.php/news/create
然后是404错误提示。
我很纳闷应该不会有错啊。
代码全是用户手册里的。大侠指点一下!

解决:问题在于form_open("news/create"),函数会自动补全url,这样导致在原来的url(http://localhost/ci/index.php/news/ )后又加上了“ci/index.php/news/create ”。这样导致找不到网页的404错误。
将form_open("news/create") 替换成<form action="create" method="post" name="create">,就可以了。添加记录成功,yeah!
后来看了stblog的原代码发现它并没有用form_open()函数,而是直接写表单"<form action="" method="post" name="write_post">"。所以,form_open()应该是不太好用吧。

dickfu 发表于 2013-4-6 00:28:28

form_open的第一个参数不要再调site_url了,form_open自己会调用site_url的

chinesebear 发表于 2013-4-6 09:20:55

问题已经解决,并不是ci的方面的原因。
<h2>Create a news item</h2>

<?php echo validation_errors(); ?>

<?php //echo form_open('news/create') ?>//form_open会自动补全url,再加上原来页面的url就很长了
<form action="create" method="post" name="create">//修改后的action
<label for="title">Title</label>
<input type="input" name="title" /><br />

<label for="text">Text</label>
<textarea name="text"></textarea><br />

<input type="submit" name="submit" value="Create news item" />

</form>

chinesebear 发表于 2013-4-6 09:21:44

dickfu 发表于 2013-4-6 00:28 static/image/common/back.gif
form_open的第一个参数不要再调site_url了,form_open自己会调用site_url的

谢谢你的解答。
页: [1]
查看完整版本: form的action问题,url被追加了(已解决)