这是我的第一个问题,我是CodeIgniter的新手,并尝试在XAMPP服务器上运行登录代码。我有两种观点。
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
<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>
和控制器:
<?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');
}
}
}
现在我在我的localhost localhost/codeigniter/index.php/form/
它会打开myform视图,但是当我点击提交按钮时,网址会变为localhost/codeigniter/index.php/form/localhost/codeigniter/index.php/form/
。这意味着它附加了网址。这是一个很长的问题,只是为了澄清你的人。请帮忙。
答案 0 :(得分:2)
如果您设置了基本网址,只需更改:
<form id="myform" method="post" action="/form/myform" title="Create an Account">
到
<form id="myform" method="post" action="<?php echo base_url();?>form/myform" title="Create an Account">