8.4.2 How to save/edit varuable number of inputs in block form
Permalink
I have a DB with a table of statuses with columns status_id and status (status name). The status names are set by a user, i.e. their numbers, names and IDs are variable and non-predictable.
I need to allow the user to turn ON or OFF whichever status they want to show in a block.
In a block form I can list the statuses like
and save them in a controller like
What I can't get is how I can load the saved values during block edit.
If the statuses couldn't change, I'd simple decode the json and displayed it there instead of $XXX. But as any status can be deleted before editing the block and new ones can be created, the id="show_status[]" will no longer reference the correct value.
Would anyone know how to save and load the input values in that case?
Thank you.
I need to allow the user to turn ON or OFF whichever status they want to show in a block.
In a block form I can list the statuses like
<?php if (is_array($statuses) && count($statuses) > 0) { foreach ($statuses as $status) { ?> <div class="checkbox"> <label> <?php echo $form->checkbox('show_status[]', 1, $XXX ? '1' : '0'); echo t('Show') . ' ' . $status->getStatus(); ?> </label> </div> <?php } }
Viewing 15 lines of 16 lines. View entire code block.
and save them in a controller like
$args['data'] = json_encode($args['show_status']);
What I can't get is how I can load the saved values during block edit.
If the statuses couldn't change, I'd simple decode the json and displayed it there instead of $XXX. But as any status can be deleted before editing the block and new ones can be created, the id="show_status[]" will no longer reference the correct value.
Would anyone know how to save and load the input values in that case?
Thank you.
I'm trying to save them in controller:
where the save() is a Status class function:
I can see in the log correct IDs of the selected check boxes. But the values are not saved in the Status DB table, I have this error:
What's wrong with that?