[英]Code Igniter URL appending
This is my first question, I am new at CodeIgniter and trying to run a login code at XAMPP server. 这是我的第一个问题,我是CodeIgniter的新手,正在尝试在XAMPP服务器上运行登录代码。 I have two views.
我有两种看法。
myform.php myform.php
<html>
<head>
<title>My Form</title>
</head>
<body>
<?php echo validation_errors(); ?>
<form id="myform" method="post" action="/form/myform" title="Create an Account">
<h5>Username</h5>
<input type="text" name="username" value="<?php echo set_value('username'); ?>" size="50" />
<h5>Password</h5>
<input type="text" name="password" value="<?php echo set_value('username'); ?>" size="50" />
<div><input type="submit" value="Submit" /></div>
</form>
</body>
</html>
formsuccess.php formsuccess.php
<html>
<head>
<title>My Form</title>
</head>
<body>
<h3>Your form was successfully submitted!</h3>
<p><?php echo anchor('form', 'Try it again!'); ?></p>
</body>
</html>
and a controller: 和一个控制器:
<?php
class Form extends CI_Controller {
public function index()
{
$this->load->helper(array('form','url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'required',
array('required' => 'You must provide a %s.')
);
if ($this->form_validation->run() == FALSE)
{
$this->load->view('myform');
}
else
{
$this->load->view('formsuccess');
}
}
}
Now when I run this on my localhost localhost/codeigniter/index.php/form/
现在,当我在本地
localhost/codeigniter/index.php/form/
上运行此命令时
it opens myform view but when I click on the submit button the URL becomes localhost/codeigniter/index.php/form/localhost/codeigniter/index.php/form/
. 它打开了myform视图,但是当我单击“提交”按钮时,URL变为
localhost/codeigniter/index.php/form/localhost/codeigniter/index.php/form/
。 It means it appends the url. 这意味着它将附加URL。 It's a long question just to clarify you people.
只是为了澄清您的人,这是一个漫长的问题。 Please help.
请帮忙。
If you set your base url, just change : 如果您设置基本网址,则只需更改:
<form id="myform" method="post" action="/form/myform" title="Create an Account">
to 至
<form id="myform" method="post" action="<?php echo base_url();?>form/myform" title="Create an Account">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.