Buy Now
Sign in

POST DATA on Json code for "Autocompleter"

andreasuriani , September 21 2017
A
andreasuriani
Hi All,
i have this problem:

i'm opening a form passed data POST the string [azienda
  • (is a number code, on this case: 406)
    I'm trying to create a Json code for Autocompleter with this data but it doesn't work.
    If i print DATAPOST on a form, works fine, but in Json not.

    This is my Json code for autocompleter:


    <?php
    $cod_azie = $_POST['azienda'];
    $db = JFactory::getDbo();
    $db->setQuery("SELECT * FROM xcsri_ana_intranet WHERE
    cod_azie = $cod_azie
    ");
    $results = $db->loadObjectList();
    foreach($results as $result ){
      if(!empty($form->data['tag']) AND stripos($result->nominativo, $form->data['tag']) === false){
        continue;
      }
      $json
  • = array('id' => $result->id, 'text' => $result->nominativo);
    }
    echo json_encode($json);


    Any ideas?
    A
    andreasuriani
    i forget ot say: if i write $cod_azie = 406; it works........
    GreyHead
    Hi andreasuriani,

    You haven't defined $json anywhere - that will give a problem with recent PHP versions. Try
    $results = $db->loadObjectList();
    $json = array();
    . . .


    Bob
    ChronoForms technical support
    If you'd like to buy me a coffee or two, thank you very much
    A
    andreasuriani
    Hi Bob,
    sorry to be late

    I've tried but unfortunately doesn't work.


    <?php

    $cod_azie = $_POST['cod_azie'
  • ;
    $db = JFactory::getDbo();
    $db->setQuery("SELECT * FROM xcsri_ana_intranet WHERE cod_azie = '" . $cod_azie . "' AND check_conguagliato IS NULL ORDER BY nominativo ASC");
    $results = $db->loadObjectList();
    $json = array();

    foreach($results as $result ){
      if(!empty($form->data['tag']) AND stripos($result->nominativo, $form->data['tag']) === false){
        continue;
      }
      $json
  • = array('id' => $result->codice_fiscale, 'text' => $result->nominativo);
    }
    echo json_encode($json);




    Why?
    GreyHead
    Hi andreasuriani ,

    I've no idea, I suggest that you add some debug code to echo out some of your intermediate steps so that you can see exactly what is happening.

    Bob
    ChronoForms technical support
    If you'd like to buy me a coffee or two, thank you very much