Reputation: 407
I was hoping for another set of eyes on my code as I cannot figure out why my post data is only accepting the first character of the input field.
Here is my view:
<form id="SearchTerm" accept-charset="utf-8" method="post" action="<?php echo site_url("record/search/"); ?>">
<input name="SearchTerm" type="text"> | <input type="submit">
</form>
And my controller:
public function search($SearchTerm = 0)
{
// Set Session Varaible
$CompanyId = $this->session->userdata('CompanyId');
$p_data = $this->input->post('SearchTerm');
if($p_data) {
$SearchTerm = $p_data['SearchTerm'];
} else {
$SearchTerm = '0';
}
var_dump($SearchTerm);
When I dump the $SearchTerm, only the first character of the input field is being caught. Do you pro coders have any suggestions?
Thank you in advance!
Upvotes: 0
Views: 149
Reputation: 219884
$p_data = $this->input->post('SearchTerm');
gets you the value of $_POST['SearchTerm']
. So calling $SearchTerm = $p_data['SearchTerm'];
is unnecessary and probably what is causing your issue.
$p_data = $this->input->post('SearchTerm');
if(!$p_data) {
$SearchTerm = '0';
}
But the last if statement is probably unnecessary as well since $this->input->post('SearchTerm')
will return false if $_POST['SearchTerm']
is empty.
Upvotes: 2