Select Not Saving Block Attribute.
Permalink 1 user found helpful
Ok, I am working on make a block that will list pages by CollectionType as well as limit the pages, and some ordering functions. But right now I am stuck on why my $form->select function is not saveing. I've been working on this issue for about 2 days now and I can't figure it out. I've tryed alot of varations. I'll post all of my code. But the first 2 forms save. Cool you know. But my select list is not saveing. Anyone that can help me I will so give you Lots of kudo's. Thanks for at least reading this.
Add/Edit (event_list_form.php)
Controller.php
db.xml
view.php
Add/Edit (event_list_form.php)
<?php defined('C5_EXECUTE') or die("Access Denied."); $block = $controller; ?> <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>Title</h2> <?php echo $form->text('title', $title, array('style' => 'width: 95%;'));?> <h2>Number and Types of Pages</h2> <?php echo t('Display '); echo $form->text('max', $max); echo t(' Pages of type');
Viewing 15 lines of 24 lines. View entire code block.
Controller.php
<?php defined('C5_EXECUTE') or die("Access Denied."); class EventListBlockController extends BlockController { protected $btName = 'Event List'; protected $btDescription = 'This is an event block that will display events either upcomming from the past.'; protected $btTable = 'btEventBlock'; protected $btInterfaceWidth = "700"; protected $btInterfaceHeight = "450"; public $title = ""; public $max = ""; public $ctID = ""; public $orderBy = ""; public function getPages() { $pages = $this->getPagesByHandle("event");
Viewing 15 lines of 47 lines. View entire code block.
db.xml
<?xml version="1.0"?> <schema version="0.3"> <table name="btEventBlock"> <field name="bID" type="I"><key /><unsigned /></field> <field name="title" type="C" size="255"></field> <field name="max" type="I"></field> <field name="ctID" type="I2"></field> <field name="orderBy" type="C" size="32"> <descr>Was enum, chrono_asc','chrono_desc'</descr> </field> <field name="displayType" type="C" size="32"> <descr>Was enum, up_coming','past','all'</descr> </field> </table> </schema>
view.php
<?php defined('C5_EXECUTE') or die("Access Denied."); $th = Loader::helper('text'); $url=Loader::helper('navigation'); Loader::model('page_list'); $pl = new PageList(); $block = $controller; $test = $block->getPages(); echo $title; echo $ctID; echo $orderBy; echo $max; ?> <div> <?php
Viewing 15 lines of 25 lines. View entire code block.
I would like to add I still haven't figured this out
I understand you say your problem is that the value for your select is not saving but where is your save function?
From what I understand from the Concrete tutorials is that the data in the fields should save automatically if they have matching ID's with the DB.xml. 2 of the values do save, but the rest are not. So I am kinda confused on why they don't save.
They state that you don't need to add a custom save function in most cases. Is this an exception? If so then what defines what will need a custom save function.
They state that you don't need to add a custom save function in most cases. Is this an exception? If so then what defines what will need a custom save function.
I'm also trying to figure this out. In the edit.php I have:
Then in my controller I want to catch the result and save
But no value, guess I'm missing something here in the save function.
Then in my controller I want to catch the result and save
public function save($data) { $args['display_type'] = $data['display_type']; parent::save($args); }
But no value, guess I'm missing something here in the save function.
@delconis
your code seems to have a problem. In the controller you have
Then you have
the $ctID you have first and the $this->ctID you have in the view function are the same variable so as far as I can see, since you're not setting it anywhere, it's value is always "" so empty.
In your view.php when you echo it, it won't show anything.
@terryoleary
the little bit of code you are showing seems correct, the problem must be somewhere else.
You might want to get rid of the quotation marks around the numbers in your select though. They represent array indexes, they should just be integers.
your code seems to have a problem. In the controller you have
public $ctID = "";
Then you have
public function view() { $this->set('title', $this->title); $this->set('ctID', $this->ctID); $this->set('orderBy', $this->orderBy); $this->set('max', $this->max); }
the $ctID you have first and the $this->ctID you have in the view function are the same variable so as far as I can see, since you're not setting it anywhere, it's value is always "" so empty.
In your view.php when you echo it, it won't show anything.
@terryoleary
the little bit of code you are showing seems correct, the problem must be somewhere else.
You might want to get rid of the quotation marks around the numbers in your select though. They represent array indexes, they should just be integers.