Issue with custom block saving
Permalink
Hi,
I've created a custom block with a single select/dropdown with three options.
I have some PHP in my view file with an if statement to check which option was selected.
When I change to option 2 or 3 in the select box and save and publish the page I can tell from the HTML I am rendering out in view, that it's working fine.
If I edit the block again the only issue is that the select box/dropdown in the edit block popup is always just the first option - it doesn't remember the chosen option.
I've attached the view and controller, what do I need to do to make it save the chosen option?
Thanks
Dave
I've created a custom block with a single select/dropdown with three options.
I have some PHP in my view file with an if statement to check which option was selected.
When I change to option 2 or 3 in the select box and save and publish the page I can tell from the HTML I am rendering out in view, that it's working fine.
If I edit the block again the only issue is that the select box/dropdown in the edit block popup is always just the first option - it doesn't remember the chosen option.
I've attached the view and controller, what do I need to do to make it save the chosen option?
Thanks
Dave
Hi,
Thanks for the reply, here is my form_setup_html.php, is this what you need? :
Thanks for the reply, here is my form_setup_html.php, is this what you need? :
<?php defined('C5_EXECUTE') or die(_("Access Denied.")); $al = Loader::helper('concrete/asset_library'); $ah = Loader::helper('concrete/interface'); ?> <style type="text/css" media="screen"> .ccm-block-field-group h2 { margin-bottom: 5px; } .ccm-block-field-group td { vertical-align: middle; } </style> <div class="ccm-block-field-group"> <h2>Select Type</h2> <div class="input"> <select name="ringtype" id="ringtype"> <option value="WEDDING" <?php if ($type == 'WEDDING') { ?> selected<?php } ?>><?php echo t('Wedding Rings')?></option> <option value="ENGAGEMENT" <?php if ($type == 'ENGAGEMENT') { ?> selected<?php } ?>><?php echo t('Engagement Rings')?></option>
Viewing 15 lines of 19 lines. View entire code block.
The problem was the variable name you were testing. You were using "$type" instead of "$ringtype".
<div class="ccm-block-field-group"> <h2><?php echo t('Select Type'); ?></h2> <div class="input"> <select name="ringtype" id="ringtype"> <option value="WEDDING" <?php if ($ringtype == 'WEDDING') { ?> selected<?php } ?>><?php echo t('Wedding Rings'); ?></option> <option value="ENGAGEMENT" <?php if ($ringtype == 'ENGAGEMENT') { ?> selected<?php } ?>><?php echo t('Engagement Rings'); ?></option> <option value="ETERNITY" <?php if ($ringtype == 'ETERNITY') { ?> selected<?php } ?>><?php echo t('Eternity Rings'); ?></option> </select> </div> </div>
Ah brilliant, nice one, thank you so much for your help! :)
Dave
Dave
Are you using the concrete5 form helper?
Most likely the problem is that you aren't giving the select the last value stored in the database.
Can you paste the section of your form here in [code] tags?