lagogz
(Lagocamanho)
January 24, 2014, 8:11am
1
Hi all.
I’m trying to collect POST values from a checkBoxList, but I’m can’t.
The field I want to take isn’t a boolean. It’s a integer to message types.
For example:
Message Type 1 -> value 1
Message Type 2 -> value 2
Message Type 3-> value 3
My model rules:
array('message_type_id', 'required'),
array('message_type_id', 'numerical', 'integerOnly'=>true),
My form view:
echo $form->checkBoxListRow(
$model,
'message_type_id',
CHtml:listData(
MessageTypes::model()->findAll(
array('order'=>'name_message_type
ASC')),
'message_type_id',
'name_message_type')
);
When I submit the form I can’t get the values for this attribute.
Anyone can help me?
I’m using YiiBooster, but I could do it without it.
Thanks.
konapaz
(Konapaz)
January 24, 2014, 10:36am
2
Hi
check with firebug the generated name of checkBoxListRow
what is the results? This name should be used in controller to collect this data
bevalorous
(Belorussov Vadim)
January 24, 2014, 10:50am
3
I could be wrong, but maybe this error is happening because you are using different names for attribute in model validation rules (‘message_type’) and in your form view (‘message_type_id’).
lagogz
(Lagocamanho)
January 24, 2014, 11:04am
4
I was wrong to write that. It’s called “message_type_id”.
This is generated code:
<label class="error required" for="Messages_mesage_type_id">
Message Type Id
<span class="required">*</span>
</label>
<input id="ytMessages_message_type_id" type="hidden"
name="Messages[message_type_id]" value="dsasad">
<span id="Messages_mesage_type_id">
<label class="checkbox">
<input id="Messages_message_type_id_0"
class="error" type="checkbox"
name="Messages[message_type_id][]"
value="2" hint="<strong>Note:
</strong> Labels surround all the
options for much larger click
areas.">
description 1
</label>
<label class="checkbox">
<input id="Messages_message_type_id_1"
class="error" type="checkbox"
name="Messages[message_type_id][]"
value="1" hint="<strong>Note:
</strong> Labels surround all the
options for much larger click
areas.">
description 2
</label>
</span>
<div class="help-block error">Error.</div>
I had already reviewed that and I think everything is correct.
The problem is that this checkboxes doesn’t appear in $_POST.
Thanks.
konapaz
(Konapaz)
January 24, 2014, 11:08am
5
lagogz:
I was wrong to write that. It’s called “message_type_id”.
This is generated code:
<label class="error required" for="Messages_mesage_type_id">
Message Type Id
<span class="required">*</span>
</label>
<input id="ytMessages_mesage_type_id" type="hidden" name="Messages[mesage_type_id]" value="dsasad">
<span id="Messages_mesage_type_id">
<label class="checkbox">
<input id="Messages_mesage_type_id_0" class="error" type="checkbox" name="Messages[mesage_type_id][]" value="2" hint="<strong>Note:</strong> Labels surround all the options for much larger click areas.">
description 1
</label>
<label class="checkbox">
<input id="Messages_mesage_type_id_1" class="error" type="checkbox" name="Messages[mesage_type_id][]" value="1" hint="<strong>Note:</strong> Labels surround all the options for much larger click areas.">
description 2
</label>
</span>
<div class="help-block error">Error.</div>
I had already reviewed that and I think everything is correct.
The problem is that this checkboxes doesn’t appear in $_POST.
Thanks.
var_dump ($_POST);
is there something like that ?
Messages…mesage_type_id…
Also is the checkboxes inside to post form ?
lagogz
(Lagocamanho)
January 24, 2014, 11:16am
6
I’m a perfect fool!!!!!!!!!!!!!!!!!!!!!!
I was editing my form, and I had not deleted this line:
<?php echo $form->textFieldRow($model,'message_type_id',array('class'=>'span5')); ?>
Therefore, I’m was overriting the attribute!!!!!!!!!!!!!
My code is OK.
Thanks all.