我在表单验证后遇到重定向问题。我在不同的视图中有 3 个不同的表单,验证后,如果表单无法提交,我想将其重定向到上一个登录页面。它工作正常,但是,如果我单击 url 并按 enter,则在提交表单后。当我在主页时,它会重定向到联系人。我希望它将其重定向到他提交的上一个登录页面。我认为这不是正确的做法,在此先感谢
myform1.php 我的 Form1
<?php echo validation_errors(); ?>
<?php echo form_open('con/validate_form'); ?>
<h5>Username</h5>
<input type="text" name="username" value="" size="50" />
<h5>Password</h5>
<input type="text" name="password" value="" size="50" />
<h5>Password Confirm</h5>
<input type="text" name="passconf" value="" size="50" />
<h5>Email Address</h5>
<input type="text" name="email" value="" size="50" />
<div><input type="submit" name='submit1' value="Submit1" /></div>
</form>
</body>
</html>
myform2.php
<html>
<head>
<title>My Form</title>
</head>
<body>
<?php echo validation_errors(); ?>
<?php echo form_open('con/validate_form'); ?>
<h5>Username</h5>
<input type="text" name="username" value="" size="50" />
<h5>Password</h5>
<input type="text" name="password" value="" size="50" />
<h5>Password Confirm</h5>
<input type="text" name="passconf" value="" size="50" />
<h5>Email Address</h5>
<input type="text" name="email" value="" size="50" />
<div><input type="submit" name-'submit2' value="Submit2" /></div>
</form>
</body>
</html>
myform3.php
<html>
<head>
<title>My Form3</title>
</head>
<body>
<?php echo validation_errors(); ?>
<?php echo form_open('con/valdate_form'); ?>
<h5>Username</h5>
<input type="text" name="username" value="" size="50" />
<h5>Password</h5>
<input type="text" name="password" value="" size="50" />
<h5>Password Confirm</h5>
<input type="text" name="passconf" value="" size="50" />
<h5>Email Address</h5>
<input type="text" name="email" value="" size="50" />
<div><input type="submit" name="submit3" value="Submit3" /></div>
</form>
</body>
</html>
这是控制器页面
public function validate_form(){
$this->load->library('form_validation');
$this->form_validation->set_rules('firstname', 'First name', 'required');
if ($this->form_validation->run() == FALSE){
($this->input->post('submit1')=='submit1') ? $this->load->view('myform1')
: ($this->input->post('submit2')=='submit2') ? $this->load->view('myform2')
: $this->load->view('myform3');
}
else
{
$this->register();
}
}
控制器
public function myform1(){
$this->load->view('myform1');
}
public function myform2() {
$this->load->view('myform2');
}
public function myfrom3() {
$this->load->view('myform3');
}