[英]Call to undefined function post() in php controller with 2 forms - CodeIgniter
我是CodeIgniter的新手。 我有2种形式的看法。 下面是具有两种形式的视图代码
<?php echo form_open("Main/login");?>
<br /><br />
<table>
<tr>
<td valign="top"><input name="txtLoginEmail" style="width:265px; margin-right: 5px; margin-left: 5px" type="email" placeholder="Email" class="form-control"/></td>
</tr>
<tr>
<input name="txtLoginPassword" style="width:265px; margin-right: 5px; margin-left: 5px" type="password" placeholder="Password" class="form-control"/>
</td>
</tr><td>
<input id="btnSignIn" type="submit" class="btn btn-success" value="Sign In"/>
<br /><br />
</td>
</tr>
</table>
<?php echo form_close(); ?>
</div>
<div role="tabpanel" class="tab-pane" id="div_signup">
<?php echo form_open("Main/register");?>
<!-- Registration Panel -->
<br /> <br />
<table>
<tr>
<td valign="top">
<input name="txtRegisterFirstName" style="width:265px; margin-right: 5px; margin-left: 5px" type="text" placeholder="First Name" class="form-control"/>
</td>
</tr>
<tr>
<td valign="top"><br />
<input name="btnRegister" style="margin-right: 5px;" value="Register" type="submit" class="btn btn-success"/>
<br /><br />
</td>
</tr>
</table>
<?php echo form_close(); ?>
这是我的控制器代码,具有两个函数来处理两种形式。 它只是接收发布请求并尝试获取参数
public function login(){
$userEmail=$this->input->post('txtLoginEmail');
$password= $this->input->post('txtLoginPassword');
$data['username']=$userEmail;
$this->load->view('welcome_message',$data);
}
public function register()
{
$fname= $this->input->post('txtRegisterFirstName');
$lname=$this->input>post('txtRegisterLastName');
$data['fname']=$fname;
$data['lname']=$lname;
$this->load->model('Main_Model');
$this->Main_Model->register($data);
}
在运行项目时,当我提交第一个表单(主/登录)时,它可以正常工作。
但是在提交第二个表单(Main / Register)时,它将引发错误
致命错误:调用C:\\ xampp \\ htdocs \\ Voyager \\ application \\ controllers \\ Main.php中未定义的函数post()
还有什么其他方法可以处理页面中的多种形式。
请帮忙。
在构造方法中加载表单助手类。
public function __construct()
{
$this->load->helper('form');
$this->load->library('form_validation');
}
注意:-请更改$lname=$this->input>post('txtRegisterLastName');
到$lname=$this->input->post('txtRegisterLastName');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.