• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
input->get('var_name')

#1
[eluser]ELRafael[/eluser]
Hy Guys,

My view. It's a simple search form
current_url() = http://site.local/news/index
Code:
<?php echo form_open( current_url(), 'method="get"' ); ?>
  <input type="text" name="search_term" id="search_term" />
  <input type="submit" value="Go Spider, GO!" />
</form>

My Controller (news, function index())
Code:
$search_term = $this->input->get('search_term');
var_dump($search_term);

Result: Always bool(false)

The url "submited"
http://site.local/news/index?ci_csrf_tok...tuação&.....

My config.php
Code:
$config['uri_protocol']    = "AUTO";
$config['enable_query_strings'] = FALSE;

I'm using CodeIgniter 2.0 under MAMP enviroment
Can anyone help me?

Before any anwser, I know if I change the form's method to post and try to get the value using $this->input->post('search_term') will work fine.
But I really wanna use GET method, not POST. I still belive that POST method is for CHANGING ACTIONS (new user, edit data, ....)

Thanks a lot Smile

#2
[eluser]CroNiX[/eluser]
Haven't messed with it, but you might want to try setting:
$config['enable_query_strings'] = TRUE;
$config['uri_protocol'] = "QUERY_STRING";

#3
[eluser]ELRafael[/eluser]
Still no donut for me :blank:

Code:
$config['enable_query_strings'] = TRUE;
$config['uri_protocol']  = "QUERY_STRING";

Now the problem is another!!
When I open the page, and I can't submit anymore.
Click in the submit button and come back to main page (base_url()).

I just wanna use $this->input->get('var_name') :down:

I'm starting to think that CI can't work with query strings

#4
[eluser]Eric Barnes[/eluser]
I think you want this using ci2 reactor:
Code:
$config['allow_get_array']        = TRUE;
$config['enable_query_strings'] = FALSE;

#5
[eluser]ELRafael[/eluser]
Eric, still don't work.

config.php
Code:
//allow_get_array is in the TOP of file
$config['allow_get_array'] = TRUE;
$config['enable_query_strings'] = FALSE;

My form
Code:
<?php echo form_open(current_url(), 'method="get"'); ?>
<input type="text" name="search_term" class="search_term" />
</form>
The url from my form
http://site.local/news/index?ci_csrf_tok...asdasd&....

My controller
Code:
var_dump($this->input->get('search_term'));
Returns: bool(false)

I'm not using CodeIgniter Reactor.
I just did the download from codeigniter.com

I'll try to implement a Javascript (JQuery) solution.
Code:
$('form#my_form_id').submit(function(e) {
  var search_term = $('input.search_term').val();
  $.post(base_url+"news/encode_string/"+search_term, { },
    function(data) {
    search_term = data.encoded;
   }, 'json');
  e.preventDefault;
});
//news/encode_string
echo json_encode( array('encoded' => $this->encrypt->encode($this->uri->segment(3))) );

I still don't know why $this->input->get('var_name') returns false all the time.

#6
[eluser]Eric Barnes[/eluser]
Try it manually: http://yousite.com/controller/method?searchterm=test

Then in controller:
Code:
var_dump($this->input->get('searchterm'));

#7
[eluser]abedzilla[/eluser]
You must enable query string and set the uri_protocol to PATH_INFO

Code:
$config['uri_protocol']    = "PATH_INFO";
$config['enable_query_strings'] = TRUE;


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.