Yii Framework Forum: Checkbox - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Checkbox checkbox Rate Topic: ***** 1 Votes

#1 User is offline   junior yii 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 33
  • Joined: 02-February 14

Posted 02 February 2014 - 04:24 AM

halo para master.izin bergabung

saya ingin menampilkan checkbox pada sebuah form create. misal datanya diambil dari tabel 1.saya sudah berhasil menampilkan data tersebut ke dalam form create..kemudian setelah user men-check pilihan (pilihan bisa lebih dari satu) dan klik tombol create, data akan tersimpan ke tabel 2.yang ingin saya tanyakan, bagaimana caranya data yang terpilih tersimpan ke tabel 2 dengan id yang berbeda?

mohon dengan sangat pencerahannya

Attached File(s)


0

#2 User is offline   junior yii 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 33
  • Joined: 02-February 14

Posted 05 February 2014 - 07:16 AM

can somebody help me please :-[
0

#3 User is offline   i.am.vj 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 07-January 14

Posted 05 February 2014 - 01:22 PM

What is your question?
0

#4 User is offline   junior yii 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 33
  • Joined: 02-February 14

Posted 05 February 2014 - 05:32 PM

 i.am.vj, on 05 February 2014 - 01:22 PM, said:

What is your question?


whats my question?? pertanyaannya kan udah diatas gan..

 junior yii, on 02 February 2014 - 04:24 AM, said:

halo para master.izin bergabung

saya ingin menampilkan checkbox pada sebuah form create. misal datanya diambil dari tabel 1.saya sudah berhasil menampilkan data tersebut ke dalam form create..kemudian setelah user men-check pilihan (pilihan bisa lebih dari satu) dan klik tombol create, data akan tersimpan ke tabel 2.yang ingin saya tanyakan, bagaimana caranya data yang terpilih tersimpan ke tabel 2 dengan id yang berbeda?

2014-02-02_162057.jpg

mohon dengan sangat pencerahannya

Attached File(s)


0

#5 User is offline   daudtm 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 91
  • Joined: 25-April 13
  • Location:Malang

Posted 06 February 2014 - 09:09 PM

 junior yii, on 05 February 2014 - 05:32 PM, said:

whats my question?? pertanyaannya kan udah diatas gan..


coba diulangi lagi dengan redaksional berbeda, kalo perlu sertakan nama model/tabel biar yg mo bantu dapat gambaran lebih jelas apa yang mau anda capai.
0

#6 User is offline   junior yii 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 33
  • Joined: 02-February 14

Posted 07 February 2014 - 09:16 AM

 daudtm, on 06 February 2014 - 09:09 PM, said:

coba diulangi lagi dengan redaksional berbeda, kalo perlu sertakan nama model/tabel biar yg mo bantu dapat gambaran lebih jelas apa yang mau anda capai.


iya gan...intinya saya punya form di view gini :
<div class="form">
<?php
$form=$this->beginWidget('CActiveForm', array(
'id'=>'kirim-form',
'enableAjaxValidation'=>false,
));?>
<?php echo $form->errorSummary($model); ?>
..........
<div class="checkboxgroup">
<?php echo $form->labelEx($model,'Kepada'); ?>
<?php echo CHtml::activeCheckBoxList( $model,'id_penerima',
CHtml::listData(Jabatan::model()->findAll(),'id_jabatan','jabatan'),
array(
'separator'=>'',
'template'=>'<div>{input} {label}</div>'
)); ?>
</div>
............
<div class="row buttons">
<p style="text-align:center"><?php echo CHtml::submitButton($model->
isNewRecord ? 'Kirim' : 'Kirim'); ?>
</div>


Checkbox datanya diambil data TABEL JABATAN..nanti setelah di submit, id nya masuknya ke TABEL KIRIM. Tapi waktu submit...peringatannya gini :
"Please fix the following input errors: Penerima must be an integer."


mohon bantuan gan..
0

#7 User is offline   junior yii 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 33
  • Joined: 02-February 14

Posted 09 February 2014 - 12:28 AM

anyone?
0

#8 User is offline   daudtm 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 91
  • Joined: 25-April 13
  • Location:Malang

Posted 10 February 2014 - 10:56 PM

 junior yii, on 07 February 2014 - 09:16 AM, said:

iya gan...intinya saya punya form di view gini :
...
Checkbox datanya diambil data TABEL JABATAN..nanti setelah di submit, id nya masuknya ke TABEL KIRIM. Tapi waktu submit...peringatannya gini :
"Please fix the following input errors: Penerima must be an integer."


mohon bantuan gan..


kalo kamu pake activeCheckBoxList untuk id_penerima, kemungkinan besar waktu submit itu isinya array, mestinya id_penerima hanya 1 kan isinya?
mungkin sebaiknya pake temporary field misalnya
<?php echo CHtml::checkBoxList('daftar_penerima',
CHtml::listData(Jabatan::model()->findAll(),'id_jabatan','jabatan'),
array(
'separator'=>'',
'template'=>'<div>{input} {label}</div>'
)); ?>


ntar di controller diterima submitnya lalu dilooping satu persatu untuk disimpan:
$daftar_penerima = $_POST['daftar_penerima'];
foreach ($daftar_penerima as $id_penerima) {
  $model = new Kirim;
  $model->attributes = $_POST['Kirim'];
  $model->id_penerima = $id_penerima;
  $model->save();
}


konsepnya begitu, tapi ntar prakteknya jangan lupa validasi dulu, ada kemungkinan data gagal simpan
0

#9 User is offline   junior yii 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 33
  • Joined: 02-February 14

Posted 11 February 2014 - 11:44 PM

 daudtm, on 10 February 2014 - 10:56 PM, said:

kalo kamu pake activeCheckBoxList untuk id_penerima, kemungkinan besar waktu submit itu isinya array, mestinya id_penerima hanya 1 kan isinya?
mungkin sebaiknya pake temporary field misalnya
<?php echo CHtml::checkBoxList('daftar_penerima',
CHtml::listData(Jabatan::model()->findAll(),'id_jabatan','jabatan'),
array(
'separator'=>'',
'template'=>'<div>{input} {label}</div>'
)); ?>


ntar di controller diterima submitnya lalu dilooping satu persatu untuk disimpan:
$daftar_penerima = $_POST['daftar_penerima'];
foreach ($daftar_penerima as $id_penerima) {
  $model = new Kirim;
  $model->attributes = $_POST['Kirim'];
  $model->id_penerima = $id_penerima;
  $model->save();
}


konsepnya begitu, tapi ntar prakteknya jangan lupa validasi dulu, ada kemungkinan data gagal simpan


berhasil tersimpan adan daudtm..tapi hanya tersimpan 1 penerima di field id_penerima dan field daftar_penerimanya kosong.saya coba tambahkan ini :
$daftar_penerima=explode(",",$_POST['Kirim']['daftar_penerima']);


muncul :
explode() expect parameter 2 to be string, array given
..

How gan?
0

#10 User is offline   junior yii 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 33
  • Joined: 02-February 14

Posted 11 February 2014 - 11:49 PM

tambahan....itu pake pake activeCheckBoxList gan.trus saya ganti checkBoxList.yang muncul :
substr()expect parameter 1 to be string, onject given

0

#11 User is offline   daudtm 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 91
  • Joined: 25-April 13
  • Location:Malang

Posted 12 February 2014 - 01:47 AM

 junior yii, on 11 February 2014 - 11:49 PM, said:

tambahan....itu pake pake activeCheckBoxList gan.trus saya ganti checkBoxList.yang muncul :
substr()expect parameter 1 to be string, onject given



jangan pake activeCheckBoxList, karena daftar_penerima kan cuman temporary variabel, abis pake buang. mending pake ini:
<?php echo CHtml::checkBoxList('daftar_penerima',
CHtml::listData(Jabatan::model()->findAll(),'id_jabatan','jabatan'),
array(
'separator'=>'',
'template'=>'<div>{input} {label}</div>'
)); ?>


coba deh, dilihat dulu hasil submitnya kayak apa, tambahin ini di controller:
  var_dump($_POST['daftar_penerima']);
//atau
  var_dump($_POST);

0

#12 User is offline   junior yii 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 33
  • Joined: 02-February 14

Posted 12 February 2014 - 02:01 AM

 daudtm, on 12 February 2014 - 01:47 AM, said:

jangan pake activeCheckBoxList, karena daftar_penerima kan cuman temporary variabel, abis pake buang. mending pake ini:
<?php echo CHtml::checkBoxList('daftar_penerima',
CHtml::listData(Jabatan::model()->findAll(),'id_jabatan','jabatan'),
array(
'separator'=>'',
'template'=>'<div>{input} {label}</div>'
)); ?>



iya gan udah pake checkBoxList....itu echo CHtml::checkBoxList($model,'daftar_penerima') ada $modelnya kan ya gan?

 daudtm, on 12 February 2014 - 01:47 AM, said:

coba deh, dilihat dulu hasil submitnya kayak apa, tambahin ini di controller:
  var_dump($_POST['daftar_penerima']);
//atau
  var_dump($_POST);



tetep gan munculnya
substr() expect parameter 1 to be string, object given

0

#13 User is offline   junior yii 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 33
  • Joined: 02-February 14

Posted 12 February 2014 - 05:36 PM

gan mau tanya kalo tetep make activeCheckboxList kan berhasil tapi tersimpan hanya 1 di id_penerima..nggak bisa array.kalo nyimpennya aja yang jadi multi rows gimana gan? misal yang diplih 3 jadi tersimpan dg 3 id yang berbeda
0

#14 User is offline   junior yii 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 33
  • Joined: 02-February 14

Posted 13 February 2014 - 09:13 AM

up...help
0

#15 User is offline   junior yii 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 33
  • Joined: 02-February 14

Posted 15 February 2014 - 12:09 AM

maksih gan..udah SOLVED ::)
0

#16 User is offline   daudtm 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 91
  • Joined: 25-April 13
  • Location:Malang

Posted 17 February 2014 - 01:55 AM

 junior yii, on 15 February 2014 - 12:09 AM, said:

maksih gan..udah SOLVED ::)


jadi akhirnya gimana solusinya, bisa dishare?
0

#17 User is offline   junior yii 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 33
  • Joined: 02-February 14

Posted 17 February 2014 - 10:23 PM

 daudtm, on 17 February 2014 - 01:55 AM, said:

jadi akhirnya gimana solusinya, bisa dishare?


tambahin ini gan :
$model->setIsNewRecord(true);
$model->id_naskah=null;
$model->save();


works fine..and SOLVED :lol:
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users