Welcome Guest, Not a member yet? Register   Sign In
post working in index, not working in another function
#1

[eluser]bartgrrr[/eluser]
Hi,

I have a JQuery autocomplete field that needs to be filled with some content of a MySQL database.
I'm unable to read the input of the user. This input is the argument of my select statement in order to narrow down the results.

1. My form contains:

Code:
<?=form_input(array('name' => 'zipcodecity', 'id' => 'zipcodecity',  'class' => 'tb', 'value' => set_value('zipcodecity')))?>

resulting in:
Code:
<input type="text" class="tb ui-autocomplete-input" id="zipcodecity" value="" name="zipcodecity" autocomplete="off">



2. My Jquery autocomplete stuff:

$("#zipcodecity").autocomplete( { source: 'berekenen/zipcodeCityPicker' } );



3. My Controller contains:
Code:
public function zipcodeCityPicker()
{
  log_message('debug', 'Controller::Berekenen::zipcodeCityPicker()');
  
  $this->load->model('zipcode');

  $val = $this->input->post('zipcodecity');
  //$val = 2880;
  //$val = 'bo';
  if(is_numeric($val)) {
   $this->zipcode->get_zipcode_city_by_zipcode($val);
  } else {
   $this->zipcode->get_zipcode_city_by_city($val);
  }
}

If I use 2880 as argument value, I get a an autocomplete list of all zipcodes containing 2880. If I use 'bo' as argument value, I get an autocomplete list of all cities containing 'bo'.
I conclude there are no problems on data access / filling the autocomplete list.
I conclude there's a problem on retrieving the filled in characters, so there's a problem on getting the values from POST.

HOWEVER:

In the index method (of the same controller) EVERYTHING WORKS JUST FINE. code fragment of index method:

Code:
public function index()
  {
   log_message('debug', 'Controller::Berekenen::index()');

   $this->load->model('pensioensparen');
   $this->data['products'] = $this->pensioensparen->getProducts();
  
   if ($this->form_validation->run('module_berekenen') == FALSE)
   {
    $this->template->write_view('content', 'pages/berekenen_view', $this->data);
   }
   else
   {
    // common
    $common['zipcodecity']       = $this->input->post('zipcodecity');
    ...
   }
  }


4. My .htaccess file rewrite stuff:

Code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]


I use CodeIgniter 2.1.2, Wamp 2.2 (Apache 2.2.22 and PHP 5.4.3), JQuery 1.9.1, JQuery 1.10.1
#2

[eluser]TheFuzzy0ne[/eluser]
Welcome to the CodeIgniter forums!

Are you sure that JQuery is using POST and not GET?

Where does your controller return the data for the autocomplete function?
#3

[eluser]TheFuzzy0ne[/eluser]
And since we're posting rewrite stuff, here's mine. Smile

Code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

RewriteCond %{REQUEST_URI} ^/(system|application|html_store)
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
</IfModule>
#4

[eluser]bartgrrr[/eluser]
My controller doesn't. I based my code on the next tutorial: tutorial
#5

[eluser]TheFuzzy0ne[/eluser]
Does the rest of your site work correctly. I assume you have more controllers and each of those has more methods and they're all working fine?

Have you tried dumping the $_POST array to the log? Have you tried the same, but from your index.php, to see if it's actually being passed to the server? Obviously, logging won't work at this point, so you'll need to do something like:

Code:
file_put_contents('output.php', print_r($_POST, TRUE));

Do you have XSS cleaning enabled? Does disabling it make any difference?

Is CSRF protection enabled? Does disabling it make any difference?

Ultimately, I see no obvious reason why this shouldn't work, so I'm wracking my brain trying to figure this out.
#6

[eluser]bartgrrr[/eluser]
XSS cleaning / CSRF protection enabling/disabling doesn't change a thing.

However, my controller ectends from a controller who extends from a controller. Can this be causing the problem?
#7

[eluser]TheFuzzy0ne[/eluser]
Only if you have some code in there that's not doing what you think it's doing.

It's certainly worth checking out.
#8

[eluser]Ed Robindon[/eluser]
The jquery.ui.autocomplete uses get...
#9

[eluser]bartgrrr[/eluser]
Thanks!!! The problem is solved!!!!

The correct code is:

Code:
$("#zipcodecity").autocomplete( {
     source: 'berekenen/zipcodeCityPicker',
     method: 'POST'
    } );

instead of

Code:
$("#zipcodecity").autocomplete( {
     source: 'berekenen/zipcodeCityPicker'
    } );
#10

[eluser]TheFuzzy0ne[/eluser]
[quote author="TheFuzzy0ne" date="1363023096"]Welcome to the CodeIgniter forums!

Are you sure that JQuery is using POST and not GET?

[/quote]

*Mumble mumble...*

Be advised, that with using GET, you may run into problems with permitted_uri_chars in ./application/config/config.php




Theme © iAndrew 2016 - Forum software by © MyBB