Content block for creating a custom button

Permalink
I have a client that needs to be able to insert a button with different caption and destination url...

I have tried to reverse engineer the 'image' block as this seems to be the most similar block type to that which I need.
i.e.
add.php, offers input boxes
controller.php, constructs an html element with the values from the form.

input 1: CAPTION
input 2: DESTINATION

result:
<a href="CAPTION">DESTINATION</a>


I cannot get it to recognise the values placed in the input elements.

I am a newbie to concrete5 and not much more when it comes to php...

I'm not even sure that I have explained this properly, any help would be a great help

here is my code:

add.php
<div class="ccm-block-field-group">
    <h2><?php echo t('Button Caption')?></h2>
    <?php echo  $form->text('btnCap', array('style' => 'width: 250px')); ?>
</div>
<div class="ccm-block-field-group">
    <h2><?php echo t('Button Links to URL')?></h2>
    <?php echo  $form->text('btnDest', array('style' => 'width: 250px')); ?>
</div>


controller.php
<?php 
   defined('C5_EXECUTE') or die("Access Denied.");   
   class ButtonBlockController extends BlockController {
      protected $btInterfaceWidth = 300;
      protected $btInterfaceHeight = 440;
      protected $btTable = 'btContentLocal';
      protected $btCacheBlockOutput = false;
      protected $btCacheBlockOutputOnPost = false;
      protected $btCacheBlockOutputForRegisteredUsers = false;
      public function getBlockTypeDescription() {
         return t("Adds 1/3 width buttons with hover state.");
      }
      public function getBlockTypeName() {
         return t("Button 1/3");
      }


view.php
<?php 
defined('C5_EXECUTE') or die("Access Denied.");
echo($controller->getContentAndGenerate());
?>

shooftie
 
guythomas replied on at Permalink Reply
guythomas
Can we see your db.xml file?
RadiantWeb replied on at Permalink Reply
RadiantWeb
there is a block that dose this nicely here(at least related to pages within the site):

http://www.concrete5.org/marketplace/addons/easy-button/...

you easily can replace the images and use the included psd to generate new color and style offerings.

best

Chad
shooftie replied on at Permalink Reply
shooftie
That would appear to be the one that I need.

I'm sure that if I were to break it apart I could get it to appear the way I want.

Currently however, I have my own button that is applied to 'a.cta'. All I need it to do is to insert the values into the html...
shooftie replied on at Permalink Reply
shooftie
<?xml version="1.0"?>
<schema version="0.3">
   <table name="btButton">
      <field name="bID" type="I">
         <key />
         <unsigned />
      </field>
      <field name="btnDest" type="C" size="255"></field>
      <field name="btnCap" type="C" size="255"></field>
   </table>
</schema>
shooftie replied on at Permalink Best Answer Reply
shooftie
I've done it... Here is the answer....

add.php
<p>Enter button details.</p>
<?php
echo $form->label('btnCaption', 'Button Caption');
echo $form->text('btnCaption', array('style' => 'width: 300px'));
echo $form->label('btnURL', 'URL');
echo $form->text('btnURL', array('style' => 'width: 300px;'));
?>


controller.php
<?php
   defined('C5_EXECUTE') or die(_("Access Denied."));
   class ButtonBlockController extends BlockController {
      protected $btDescription = "Build a simple 1/3 width button with hover effect";
      protected $btName = "BCS Button";
      protected $btTable = 'btButton';
      protected $btInterfaceWidth = "400";
      protected $btInterfaceHeight = "500";
      function save($args){
         parent::save($args);
      }
   }
?>


view.php
<?php
   defined('C5_EXECUTE') or die(_("Access Denied."));
?>
   <a href="<?php echo $btnURL;?>" class="cta"><?php echo $btnCaption;?></a>


db.xml
<?xml version="1.0"?>
<schema version="0.3">
   <table name="btButton">
      <field name="bID" type="I">
         <key />
         <unsigned />
      </field>
      <field name="btnCaption" type="C" size="255">
      </field>
      <field name="btnURL" type="C" size="255">
      </field>
   </table>
</schema>
chrismodlao replied on at Permalink Reply
chrismodlao
Hi,
Can you also share the content of : edit.php

thanks in advance, your button work pretty well but need to be able to edit it after.

Chris
shooftie replied on at Permalink Reply
shooftie
Chris,

I was working at an agency whilst doing this work and I do not have access to the code any longer.

Additionally, this was the one and only time that I've worked with Concrete5 and 6 years passing has left me with nothing but remnant understanding of its workings.

Really sorry mate.
chrismodlao replied on at Permalink Reply
chrismodlao
No Prob.
If i get the solution i will post i here

Chris
mnakalay replied on at Permalink Reply
mnakalay
If you are on Concrete5 5.7 there are 2 add-ons in the marketplace that create buttons.

Buttons Pro:http://www.concrete5.org/marketplace/addons/buttons-pro...
ProButton:http://www.concrete5.org/marketplace/addons/probutton...

Yeah I know, the naming is confusing :)

Full disclosure: the first one mine but it is also the most flexible by far.

If you are on Concrete5 5.6 I believe proButton also has a version for old C5.