Adding a Radio button Class selector to Image Block
Permalink
Hi I'm fairly new to PHP, but getting there... what i'm trying to achieve is to adapt the image block in concrete to have an extra section with a series of 4 radio buttons:
Reflect image? No reflection, 33%, 66%, 100%
This then need to write back to the database and then I need to pull out the info and assign a different class depending upon the option selected. I have managed to create the radio buttons, but there are neither saving no affecting the code correctly.
Thanks in advance for your help.
Code i'm using is as follows:
in add/edit.php
in db.xml
and in controller.php line 44
and in controller.php lines 71-89
Reflect image? No reflection, 33%, 66%, 100%
This then need to write back to the database and then I need to pull out the info and assign a different class depending upon the option selected. I have managed to create the radio buttons, but there are neither saving no affecting the code correctly.
Thanks in advance for your help.
Code i'm using is as follows:
in add/edit.php
<div class="ccm-block-field-group"> <h2><?php echo t('Reflect Image?')?></h2> <?php if($reflect == 4){$r= true;} elseif($reflect == 1){$rr= true;} elseif($reflect == 2){$rrr= true;} elseif($reflect == 3){$rrrr= true;} else {$r= true;} ?> <?php echo $form->radio('reflect','4', $r);?> <?php echo t('No Reflection');?> <?php echo $form->radio('reflect','1', $rr);?> <?php echo t('33%');?> <?php echo $form->radio('reflect','2', $rrr);?> <?php echo t('66%');?> <?php echo $form->radio('reflect','3', $rrrr);?> <?php echo t('100%');?> </div>
in db.xml
<field name="reflect" type="I"> </field>
and in controller.php line 44
and in controller.php lines 71-89
$img = "<img border=\"0\" alt=\"{$this->altText}\" src=\"{$relPath}\" {$sizeStr} "; $img .= ($align) ? "align=\"{$align}\" " : ''; $img .= ($reflect) ? "class=\"{$reflect}\" " : ''; if ($this->reflect > 1){ echo 'ccm-image-block reflect rheight33' ; } if ($this->reflect > 2){ echo 'ccm-image-block reflect rheight66' ; } if ($this->reflect > 3){ echo 'ccm-image-block reflect rheight100' ; } else { echo 'ccm-image-block' ; }
Hi ukao
Thanks for your answer, however it doesn't appear to be doing the trick. I have tried refreshing the database schema, i've put in the code, but the database doesn't seem to be storing the info. If i edit it and select a radio button and then update then when i re edit no radio button is selected.
The source for the page just shows the following:
Any other advice would be greatly appreciated. Regards
Thanks for your answer, however it doesn't appear to be doing the trick. I have tried refreshing the database schema, i've put in the code, but the database doesn't seem to be storing the info. If i edit it and select a radio button and then update then when i re edit no radio button is selected.
The source for the page just shows the following:
<img border="1" alt="" src="/~admin14/files/3412/7117/3110/image.jpg" width="334" height="437" class="ccm-image-block" />
Any other advice would be greatly appreciated. Regards
Can you access your database to see if the 'reflect' field is showing up?
Hi ukao
I have access to the database, however i don't know where i'd look to find out.
Cheers
I have access to the database, however i don't know where i'd look to find out.
Cheers
Look in the table 'btcontentimage' in your concrete5 database.
Hi ukao, Excellent work!
The database didn't seem to have the reflect field in it, so I added the field and voila! Thank you for your help.
The database didn't seem to have the reflect field in it, so I added the field and voila! Thank you for your help.
You have some redundant code in the add/edit.php, this would do the same thing with less code
and your code in controller.php lines 71-89 does not quite make sense, but I think this is what you are looking to do