Concrete5 表单 -> 复选框无法正常工作
Concrete5 form->checkboxes not working correctly
我是 concrete5 和 PHP 的新手。
DB.XML
<!-- features for Row 1 -->
<field name="PC_Row_1_Feature_1_Enabled" type="L">
<default value="0" />
<unsigned/>
</field>
<field name="PC_Row_1_Feature_2_Enabled" type="L">
<default value="0" />
<unsigned/>
</field>
<field name="PC_Row_1_Feature_3_Enabled" type="L">
<default value="0" />
<unsigned/>
</field>
<field name="PC_Row_1_Feature_4_Enabled" type="L">
<default value="0" />
<unsigned/>
</field>
<!-- features for Row 2 -->
<field name="PC_Row_2_Feature_1_Enabled" type="L">
<default value="0" />
<unsigned/>
</field>
<field name="PC_Row_2_Feature_2_Enabled" type="L">
<default value="0" />
<unsigned/>
</field>
<field name="PC_Row_2_Feature_3_Enabled" type="L">
<default value="0" />
<unsigned/>
</field>
<field name="PC_Row_2_Feature_4_Enabled" type="L">
<default value="0" />
<unsigned/>
</field>
edit.php
<?php
echo $form->checkbox("PC_Row_1_Feature_1_Enabled", 1, $PC_Row_1_Feature_1_Enabled);
?>
<?php
echo $form->checkbox("PC_Row_1_Feature_2_Enabled", 1, $PC_Row_1_Feature_2_Enabled);
?>
<?php
echo $form->checkbox("PC_Row_1_Feature_3_Enabled", 1, $PC_Row_1_Feature_3_Enabled);
?>
<?php
echo $form->checkbox("PC_Row_1_Feature_4_Enabled", 1, $PC_Row_1_Feature_4_Enabled);
?>
<?php
echo $form->checkbox("PC_Row_2_Feature_1_Enabled", 1, $PC_Row_2_Feature_1_Enabled);
?>
<?php
echo $form->checkbox("PC_Row_2_Feature_2_Enabled", 1, $PC_Row_2_Feature_2_Enabled);
?>
<?php
echo $form->checkbox("PC_Row_2_Feature_3_Enabled", 1, $PC_Row_2_Feature_3_Enabled);
?>
<?php
echo $form->checkbox("PC_Row_2_Feature_4_Enabled", 1, $PC_Row_2_Feature_4_Enabled);
?>
我也试过:
echo $form->checkbox('PC_Row_1_Feature_3_Enabled', $PC_Row_1_Feature_3_Enabled, false);
还认为也许一点 JS 会有所帮助
$('.checkbox input').on('click',function(){
if($(this).val() == "0"){
$(this).val('1');
$(this).prop('checked', true);
} else {
$(this).val('0');
$(this).prop('checked', false);
}
});
要更改值并取消选中等...
view.php
<?php if($PC_Row_2_Feature_1_Enabled == "1") { ?>
<img class="ui centered image" src="<?php echo $this->getThemePath() ?>/images/tick_mark.png">
<?php } ?>
我遇到的问题是,当我选中或取消选中它时,它不会在数据库中更改,然后不会显示或隐藏在视图中。我知道我可能会做错事,所以希望有具体经验的人可以帮助我。
要保存复选框值,请检查是否已在块 controller.php save() 方法中设置键。 save() 方法允许在保存到数据库之前更改 $_POST 数组数据(例如,如果您想 trim() 输入)。
示例:
public function save($args)
{
$args['checkbox_example'] = isset($args['checkbox_example']) ? 1 : 0;
parent::save($args);
}
$args 是 $_POST 数组。
- 如果设置了checkbox_example键,则值设置为1
- 如果checkbox_example键没有设置,则值设置为0
我是 concrete5 和 PHP 的新手。
DB.XML
<!-- features for Row 1 -->
<field name="PC_Row_1_Feature_1_Enabled" type="L">
<default value="0" />
<unsigned/>
</field>
<field name="PC_Row_1_Feature_2_Enabled" type="L">
<default value="0" />
<unsigned/>
</field>
<field name="PC_Row_1_Feature_3_Enabled" type="L">
<default value="0" />
<unsigned/>
</field>
<field name="PC_Row_1_Feature_4_Enabled" type="L">
<default value="0" />
<unsigned/>
</field>
<!-- features for Row 2 -->
<field name="PC_Row_2_Feature_1_Enabled" type="L">
<default value="0" />
<unsigned/>
</field>
<field name="PC_Row_2_Feature_2_Enabled" type="L">
<default value="0" />
<unsigned/>
</field>
<field name="PC_Row_2_Feature_3_Enabled" type="L">
<default value="0" />
<unsigned/>
</field>
<field name="PC_Row_2_Feature_4_Enabled" type="L">
<default value="0" />
<unsigned/>
</field>
edit.php
<?php
echo $form->checkbox("PC_Row_1_Feature_1_Enabled", 1, $PC_Row_1_Feature_1_Enabled);
?>
<?php
echo $form->checkbox("PC_Row_1_Feature_2_Enabled", 1, $PC_Row_1_Feature_2_Enabled);
?>
<?php
echo $form->checkbox("PC_Row_1_Feature_3_Enabled", 1, $PC_Row_1_Feature_3_Enabled);
?>
<?php
echo $form->checkbox("PC_Row_1_Feature_4_Enabled", 1, $PC_Row_1_Feature_4_Enabled);
?>
<?php
echo $form->checkbox("PC_Row_2_Feature_1_Enabled", 1, $PC_Row_2_Feature_1_Enabled);
?>
<?php
echo $form->checkbox("PC_Row_2_Feature_2_Enabled", 1, $PC_Row_2_Feature_2_Enabled);
?>
<?php
echo $form->checkbox("PC_Row_2_Feature_3_Enabled", 1, $PC_Row_2_Feature_3_Enabled);
?>
<?php
echo $form->checkbox("PC_Row_2_Feature_4_Enabled", 1, $PC_Row_2_Feature_4_Enabled);
?>
我也试过:
echo $form->checkbox('PC_Row_1_Feature_3_Enabled', $PC_Row_1_Feature_3_Enabled, false);
还认为也许一点 JS 会有所帮助
$('.checkbox input').on('click',function(){
if($(this).val() == "0"){
$(this).val('1');
$(this).prop('checked', true);
} else {
$(this).val('0');
$(this).prop('checked', false);
}
});
要更改值并取消选中等...
view.php
<?php if($PC_Row_2_Feature_1_Enabled == "1") { ?>
<img class="ui centered image" src="<?php echo $this->getThemePath() ?>/images/tick_mark.png">
<?php } ?>
我遇到的问题是,当我选中或取消选中它时,它不会在数据库中更改,然后不会显示或隐藏在视图中。我知道我可能会做错事,所以希望有具体经验的人可以帮助我。
要保存复选框值,请检查是否已在块 controller.php save() 方法中设置键。 save() 方法允许在保存到数据库之前更改 $_POST 数组数据(例如,如果您想 trim() 输入)。
示例:
public function save($args)
{
$args['checkbox_example'] = isset($args['checkbox_example']) ? 1 : 0;
parent::save($args);
}
$args 是 $_POST 数组。
- 如果设置了checkbox_example键,则值设置为1
- 如果checkbox_example键没有设置,则值设置为0