简体   繁体   中英

Custom checkbox in Opencart admin page is not checked

I'm trying to implement a custom feature in Opencart, so I need to add a couple of checkboxes in the backend (Admin Page). I've already done that and the settings I want are correctly being written into the database and cause exactly the result I want.

The problem I have now, is that when I'm going to change again these settings (select another checkbox), the previous status is not displayed (no matter what I've checked before, both checkboxes are shown empty).

Because I'm sure I'm doing something wrong, does anybody know where exactly?

Are you checking to see if the setting has been set? For instance:

Controller file:

if (isset($this->request->post['custom_setting'])) {
    $this->data['custom_setting'] = $this->request->post['custom_setting'];
} else {
    $this->data['custom_setting'] = $this->config->get('custom_setting');       
}   

.tpl file:

<?php if ($custom_setting) { ?>
    <input type="checkbox" value="1" checked="checked">My Setting</option>
<?php } else { ?>
    <input type="checkbox" value="1">My Setting</option>
<?php } ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM