How to insert dependent (chained) field into db

How to insert dependent (chained) field into db

vladimirijusvladimirijus Posts: 16Questions: 4Answers: 1

I have tried to create dependent country-city fields using editor 1.5.5 version. After country is selected cities list have been populated, but it is not possible to record city value into db.

Live example is here: http://backend.front.rs/chained_select.php

Chained select was working before in older versions of editor.

Vladimir

This question has an accepted answers - jump to answer

Answers

  • vladimirijusvladimirijus Posts: 16Questions: 4Answers: 1
    Answer ✓

    I have found the solution for this problem.
    Example of success part from ajax should be like this:

                success: function(results) {
                    callback( {
                        options: {
                            "towns.city_id": results
                        }
                    });             
                }
    

    results returned from server:

    [{"label":"- Select city -","value":0},{"label":"Clinton","value":"4"},{"label":"Los Angeles","value"
    :"2"},{"label":"New York","value":"1"}]
    
  • edanyildizedanyildiz Posts: 43Questions: 13Answers: 4

    Thank you vladimirijus,

    I was exactly looking for this.

  • edanyildizedanyildiz Posts: 43Questions: 13Answers: 4

    could you please share the content of ajax_select_options.php

  • vladimirijusvladimirijus Posts: 16Questions: 4Answers: 1

    Hi,
    @edanyildiz here is an example of function which I use in my php class. hope this will helps you.

    /* 
     * this function returns options which will be used in editor's 
     * drop down menu
     * /
    public function get_select_options($search_val)
    {
            $cmd = "SELECT  `id`,`your_field_title` 
                    FROM `your_table` 
                    WHERE `some_field`=:search_value 
                    ORDER BY `your_field_title`
            ";
            $params = array(':search_value'=>$search_val);           
            $sth = $this->db->prepare($cmd);
            $sth->execute($params);
            $sth->setFetchMode(PDO::FETCH_ASSOC);
           
            $OPTIONS = array();
    
            while($row = $sth->fetch()) {
                $OPTIONS[] = array(               
                    'label' => $row['your_field_title'],
                    'value' => $row['id']
                );        
            }
            return json_encode($OPTIONS);
    } 
    
This discussion has been closed.