creating a new block

Permalink
I am have installed and am modifying a new block, but I can't get it to display new form input after I hit save.

I added this code to add.php and edit.php

<div class="ccm-ui">
<?php echo $form->label('sentence', t('Input Sentence')) ?>
<?php echo $form->text('sentence') ?>
</div>

And I added this code to db.xml


<field name="sentence" type="X2">
<default value="" />
</field>

What else do I need to do to make sure that whatever I plug into Input Sentence (which appears in the edit-block screen as a form field, but doesn't display or save my input when I view the block afterward) dsiplays in the block and remains in the database table for the block?

 
jvansanten replied on at Permalink Reply
If you need to get something up and running quickly, or want an example that will generate a block for structured display and input, check out the Designer Content block -- which automates the process of creating a block which accepts variable structured complex content.

Jordan Lev has contributed this to the community. It's available at no cost at:http://www.concrete5.org/marketplace/addons/designer-content/...
wclark07 replied on at Permalink Reply 1 Attachment
UPDATE __ ALL: PLZ DISREAGARD THE FOLLOWING POST AND SKIP DOWN TO SEE CORRECT INFO BELOW.


So, it turns out that simply adding the form to the add.php and edit.php files and adding the new column for the database to the db.xml file DOES NOT automatically trigger code to make a new column in the database. So, I went into the database and added one. Now it it works. Here are the steps for newbies like myself.

1. add form to edit.php and add.php (if the form helpers are confusing just copy their syntax

2. make new fields/columns in the xml.db file

(See code above).

3. add those same columns/fields to the actual database using php my admin.


Below I am pasting all code before and after and a screenshot

<?php defined('C5_EXECUTE') or die(_("Access Denied.")) ?>
<div class="ccm-ui">
<div class="alert-message block-message info">
<?php echo t("This is the add template for the basic test block. Anything you add in this view will automatically be wrapped in a form and, when submitted, sent to the block's controller.") ?>
</div>
   <?php echo $form->label('content', t('Name')) ?>
   <?php echo $form->text('content') ?>
       </div>
        //what i added
        <div class="ccm-ui">
        <?php echo $form->label('sentence', t('Input Sentence')) ?>
        <?php echo $form->text('sentence') ?>
        </div>


<?xml version="1.0"?>
<schema version="0.3">
   <table name="btBasicTest">
      <field name="bID" type="I">
         <key ></key>
         <unsigned ></unsigned>
      </field>
      <field name="content" type="X2">
         <default value="" ></default>
      </field>
                <field name="sentence" type="X2">
         <default value="" ></default>
      </field>
   </table>
</schema>



see attached jpeg for php my admin steps
wclark07 replied on at Permalink Reply
As a side note, where should I put php/mysql code to automatically trigger the creation of a new field in the blocks database table everytime I edit the block and need new db table fields?

or is this idea counter to the idea of "make a block for a relatively specific purpose, use it for that purpose or make a new one?"
JohntheFish replied on at Permalink Reply
JohntheFish
db.xml gets re-evaluated and the database fields updated when the containing package version is incremented and the package update is run.
mhawke replied on at Permalink Reply
mhawke
After you make changes to db.xml, you can simply go to "Dashboard->Block Types". Click on your block and then click 'Refresh'. This will update the existing database tables and add your new columns. After you make changes to the table, this will apply to all the blocks that you have already placed on the site by that block. If you want to keep those old blocks just the way they were, you will need to create a new block under a new name.

More info:http://www.concrete5.org/documentation/recorded-trainings/building-...
wclark07 replied on at Permalink Reply
Thanks so much mhawke and Johnthefish.