⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Can't save data while using multiselect field



Angga Pratama

Angga Pratama
  • profile picture
  • Member

Posted 09 October 2012 - 15:13 PM

Hi,

I pick two choices through multi select field, save it, and nothing happened. Only occurs through the add operation.
But I'm not encountered this problem if I save it through the update operation.

Any help would be appreciated.

Thanks,
Angga.

web-johnny

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 09 October 2012 - 22:48 PM

Hello [member='Angga Pratama'] and welcome to the forum,

Do you have any errors? Can you please post some code please?

Cheers
Johnny

Angga Pratama

Angga Pratama
  • profile picture
  • Member

Posted 11 October 2012 - 08:15 AM

When I save the data with a click on 'Save' or 'Save and go back to list' button, it only shows a loading gif spinning, and then nothing happened. I checked the database, the data wasn't stored.

Here some code of it.


$queryact = $this->db->query("SELECT activities FROM act_marketing");
foreach ($queryact->result() as $row)
{
$arrAct[$row->activities] = $row->activities;
}
$crud_lokasi->field_type('activities','multiselect',$arrAct);


This error only happens when adding through the add operation. It works fine when using edit/update operation

Dale

Dale
  • profile picture
  • Member

Posted 12 October 2012 - 03:30 AM

I'm having the same problem. Have just installed G-crud and am working through some examples (the code is cut and paste from your examples, with database name/field changes only).

web-johnny

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 14 October 2012 - 15:12 PM

[member='Angga Pratama'] and [member='Dale'] when you have the infinite loading there is an error at your firebug. Can you please add it as a post to the forum please?

Thanks.

Dale

Dale
  • profile picture
  • Member

Posted 16 October 2012 - 03:23 AM

"NetworkError: 404 Not Found - http://localhost:8888/company/table/insert_validation"
insert



TypeError: data is null


flexigrid-add.js (line 44)

Dale

Dale
  • profile picture
  • Member

Posted 16 October 2012 - 03:25 AM

Previous post missed the middle line from the console - [...]/company/table/insert

Evandro

Evandro
  • profile picture
  • Member

Posted 13 March 2016 - 18:07 PM

I have the same problem, insert form don't work when I add multiselect field.

 

Error message:

Error Number: 1054
Unknown column 'Array' in 'field list'


INSERT INTO `curso` (`NAME`, `URL`, `DESC`, `TYPE`, `NUM`, `IMAGE`, `TEACHER`, `VALOR`, `FOR_N`, `FOR_T`, `PARC`, `DURATION_N`, `DURATION_T`, `ID_SECTION`, `STATE`, `DATE_INS`) VALUES ('a', 'a', 'a', '2', '1', '', Array, '1', '1', '1', '1', '1', '1', '', '1', '2016-03-13 10:51:30')


Filename: /models/grocery_crud_model.php
Line Number: 483
My multiselect field:
 
$query = $this->db->query('SELECT ID, NAME FROM teacher');
foreach ($query->result() as $row)
{
  $teachers[$row->ID] = $row->NAME;
}
$crud->field_type('TEACHER','multiselect', $teachers);
Can someone help me please ?

Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 14 March 2016 - 09:32 AM

can you put up the complete code of the function that you using for the same. Also, the callback methods.. so can look into and throw in some light if possible.


Evandro

Evandro
  • profile picture
  • Member

Posted 14 March 2016 - 10:26 AM

can you put up the complete code of the function that you using for the same. Also, the callback methods.. so can look into and throw in some light if possible.


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 15 March 2016 - 07:27 AM

$crud->field_type('TEACHER','multiselect', $teachers);

 

well here's where the issue is.. you have custom set the field type to multiselect. That aint relation_n_n...

thats custom field type setting. For this, what you need to do is handle the insertion or pre-insertion on your own with callback_insert / callback_before_insert

callback_insert will allow you to handle he insert on your own .. or callback_before_insert - u can set the value of the field (teacher .... if it exists) in a proper pattern which will be accepted by database.

 

Here .. of course you have customized the field type.. GC library is going to function absolutely the way it is written to handle the field inputs. It expects you to provide a valid input type which can be directly be handled by the library or it will expect you to handle the custom type yourself.

 

Happy GCing:)


Evandro

Evandro
  • profile picture
  • Member

Posted 16 March 2016 - 02:33 AM

Ops, got an error message when trying to save (using set_relation_n_n).
 
Fatal error: Uncaught exception 'Exception' with message 'On the state "insert" you must have post data' in /application/libraries/Grocery_CRUD.php:3340 Stack trace: #0 /application/libraries/Grocery_CRUD.php(4561): grocery_CRUD_States->getStateInfo() #1 /application/controllers/course.php(137): Grocery_CRUD->render() #2 /application/controllers/course.php(19): course->lista() #3 [internal function]: course->index('insert') #4 /system/core/CodeIgniter.php(359): call_user_func_array(Array, Array) #5 /index.php(202): require_once('...') #6 {main} thrown in/application/libraries/Grocery_CRUD.php on line 3340

 

and:

Error Number: 1054
Unknown column 'Array' in 'field list'

INSERT INTO `curso` (`NAME`, `URL`, `DESC`, `TYPE`, `NUM`, `IMAGE`, `TEACHER`, `VALOR`, `FOR_N`, `FOR_T`, `PARC`, `DURATION_N`, `DURATION_T`, `ID_SECTION`, `STATE`, `DATE_INS`) VALUES ('a', 'a', 'a', '2', '1', '', Array, '1', '1', '1', '1', '1', '1', '', '1', '2016-03-16 07:01:22')

Filename: /models/grocery_crud_model.php
Line Number: 483

Am I doing something wrong?

$crud->set_relation_n_n('TEACHERS','curso_teacher','teacher','ID_TEACHER','ID_CURSO','NAME');

Evandro

Evandro
  • profile picture
  • Member

Posted 17 March 2016 - 10:06 AM

I just removed the TEACHER field and it worked (no more error message).
 
If I understand you right now I need to create the callback_before_insert to insert the relationship between the tables.

Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 18 March 2016 - 06:24 AM

exactly .. u got the solution.!!

Happy GCing :)