Reputation: 4175
I am new to CodeIgniter. I have a view with 2 forms. Below is the code for view with two forms
<?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(); ?>
This is my controller code with two functions to handle two forms. It simply receives post request and try to get parameters
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);
}
While running project, When I submit first form(Main/Login) it works fine.
But while submitting second form(Main/Register), it throws error
Fatal error: Call to undefined function post() in C:\xampp\htdocs\Voyager\application\controllers\Main.php
Is there any other way I should handle multiple forms in a page.
Please help.
Upvotes: 0
Views: 3441
Reputation: 10037
Load form helper class in constructor method.
public function __construct()
{
$this->load->helper('form');
$this->load->library('form_validation');
}
Note:- Please change $lname=$this->input>post('txtRegisterLastName');
to $lname=$this->input->post('txtRegisterLastName');
Upvotes: 1