Post data into db from multiselect

5 posts, 0 answers
  1. Jack
    Jack avatar
    9 posts
    Member since:
    May 2013

    Posted 05 Feb 2014 Link to this post

    Hi!
    I have 2 datasources: for multiselect and for dropdownlist, and 1 datasource for insert data into db from multiselect and dropdownlist.
    But as result i have new record in database: id_client: blank and id_board: (needed value).
    When i do "alert(required.value() + optional.value() )" i getting needed values. Why is blank posted data in field "id_client"?


     var required = $("#multiclients").data("kendoMultiSelect");<br>            var optional = $("#ddrecord").data("kendoDropDownList");<br><br><br>            $("#mrecord").click(function() {<br>             alert(required.value() + optional.value() );<br>         var dataa = {id_client: required.value(), id_board: optional.value()};<br>        dataSR.add(dataa);<br>         dataSR.sync();<br>  }); 
  2. Jack
    Jack avatar
    9 posts
    Member since:
    May 2013

    Posted 05 Feb 2014 Link to this post

    If i do 
    var dataa = {id_client: 77, id_board: 99}
    data posted normally.
  3. Kendo UI is VS 2017 Ready
  4. Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 07 Feb 2014 Link to this post

    Hello Jack,

    Thank you for the code snippet. I noticed that in the working example a numeric value was passed. The MultiSelect's value method however, returns an array of strings which may not be recognized by the controller.
    In case the above does not answer your question I would ask you provide additional information, so we can advise you further.

    Regards,
    Alexander Popov
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  5. Jack
    Jack avatar
    9 posts
    Member since:
    May 2013

    Posted 07 Feb 2014 Link to this post

    My goal is  record 1 or more clients to fitness training.

    What i need and what i have: 
    i have multiselect with datasource (data from mysql table "clients"),
    i have dropdownlist with datasource (data from mysql table "board" (trainings)).
    I need to choose 1 or more clients and 1 training and put their id's into mysql table "record"(att. file).
    The result 1 or more new records in table "record".
  6. Jack
    Jack avatar
    9 posts
    Member since:
    May 2013

    Posted 09 Feb 2014 Link to this post

    Solved.

    var required = $("#multiclients").data("kendoMultiSelect");
    var optional = $("#ddrecord").data("kendoDropDownList");
    var req = required.value();
     
     $("#mrecord").click(function() {
     
     var dataa = {"id_client": req, "id_board": optional.value()};
    dataSR.add(dataa);
    dataSR.sync();
     
    });

    and php code:
    case 'record':
                 $columns = array('id_record', 'id_client', 'id_board');
                 switch($type) {
                       case 'create':
                               require_once 'db/DB_Functions.php';
                               $db = new DB_Functions();
                               $options = array();                      
                               $models = $request->models[0]->id_client;
                               $board = $request->models[0]->id_board;
                                 foreach($models  as  $key => $value) {
                                             $options[] =  "(NULL, $value, $board)";  }
                               $options2 = implode(", ", $options);
                               $sql = "INSERT INTO `record` (`id_rec`, `id_client`, `id_board`) VALUES $options2";
                               $result = mysql_query($sql) or die(mysql_error());
                            //$result = $result->create('record', $columns, $request->models, 'id_record');
                       break;

    Maybe it is a sh#tcode but it works, rewrite here if u want :)
Back to Top
Kendo UI is VS 2017 Ready