Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Extending a Page - Textfields in BE dont save


Go to End


2 Posts   1063 Views

Avatar
Pipifix

Community Member, 56 Posts

20 June 2011 at 11:37pm

Edited: 21/06/2011 12:06am

Hello all of you.

I got a ProductPage and want to set a claim for the Product. Additionally add some Images and a string('NameofReel') for some jquerymagic. My code/ProductPage looks like this:

<?php
/**
 * Defines the Product Page type
 */

class ProductPage extends Page {
   static $db = array(
   );
   static $has_one = array(
   	"Claim" => "Varchar",
	"BigProductImage"	=> "Image",
	"SmallProductImage"	=> "Image",
	"NameofReel" => "Varchar"
   );
   
   function getCMSFields() {
		$fields = parent::getCMSFields(); 	
		$fields->addFieldToTab("Root.Content.Main", new ImageField('BigProductImage','Gro&szlig;es Bild - oben im Produktbild'));
		$fields->addFieldToTab("Root.Content.Main", new ImageField('SmallProductImage', 'Kleines Bild - oben im Produktbild'));
		$fields->addFieldToTab("Root.Content.Main", new TextField ('Claim','Beschriftung unter dem Produktnamen(Claim)'), 'Content');
		$fields->addFieldToTab("Root.Content.Main", new TextField ('NameofReel','Name des Reels (ohne Endung)'), 'Content');
		
		return $fields;
	}
 
}

class ProductPage_Controller extends Page_Controller {
	public function init() {
		parent::init();
		Requirements::block("sapphire/thirdparty/prototype/prototype.js"); 
    		Requirements::javascript('themes/sizoobig/js/jquery-1.4.4.min.js');
		Requirements::javascript('themes/sizoobig/js/jquery.kwicks-1.5.1.pack.js');
    		Requirements::javascript('themes/sizoobig/js/jquery.reel.js');
    		Requirements::javascript('themes/sizoobig/js/globalfunctions.js');
	}

}

But the TextField in the cms wont save their strings. The Imagefields work as expected. Whats wrong? I guess its a absolute noob question but I dont see the error?

Thanks for you help. Pipifix

UPDATE:
--------------------------
I#m using SS2.45 and its a multilingual site. So i found this in the translating-docs

class Page extends SiteTree {
     
    public static $db = array(
        'AdditionalProperty' => 'Text',
    );
     
    function getCMSFields() {
        $fields = parent::getCMSFields();
 
        // Add fields as usual
        $additionalField = new TextField('AdditionalProperty');
        $fields->addFieldToTab('Root.Content.Main', $additionalField);
         
        // If a translation exists, exchange them with
        // original/translation field pairs
        $translation = $this->getTranslation(Translatable::default_locale());
        if($translation && $this->Locale != Translatable::default_locale()) {
            $transformation = new Translatable_Transformation($translation);
            $fields->replaceField(
                'AdditionalProperty',
                $transformation->transformFormField($additionalField)
            );
        }
 
        return $fields;
    }
     
}

I dont know if this causes the saving issue. How to change this code to replace both (NameofReel+Claim) Fields?
This way..?

...
 $fields->replaceField(
                'NameofReel',
                $transformation->transformFormField($reelField)
            );
 $fields->replaceField(
                'Claim',
                $transformation->transformFormField($claimField)
            );
...

BTW: I've used the alternative way from this docsnippet above to set the textfield

$additionalField = new TextField('AdditionalProperty');
$fields->addFieldToTab('Root.Content.Main', $additionalField);

That doesn't works neither!?

Avatar
Pipifix

Community Member, 56 Posts

21 June 2011 at 1:33am

It was a noob thing!

The data-attributes belongs to the database array. Not in the relations-array!
So the code have to look like this.

class ProductPage extends Page {
   static $db = array(
	'Claim' => 'Text',
	'NameofReel' => 'Text'
   );
   static $has_one = array(
		"BigProductImage"	=> "Image",
		"SmallProductImage"	=> "Image",
		'ProductPage' => 'ProductPage'
   );
   
   function getCMSFields() {
		$fields = parent::getCMSFields(); 	
		$fields->addFieldToTab("Root.Content.Main", new ImageField('BigProductImage','Gro&szlig;es Bild - oben im Produktbild'));
		$fields->addFieldToTab("Root.Content.Main", new ImageField('SmallProductImage', 'Kleines Bild - oben im Produktbild'));
		$fields->addFieldToTab("Root.Content.Main", new TextField ('Claim','Beschriftung unter dem Produktnamen(Claim)'), 'Content');
		$fields->addFieldToTab("Root.Content.Main", new TextField ('NameofReel','Name des Reels (ohne Endung)'), 'Content');
 		return $fields;
	}
}

Offtopic: This is the second post today i'm answering myself. I dont want to bother you. Maybe i'm to impatient. But i wanna give a possible solution to beginners like me. I think its better for people with a similar problem to find a code snippet then find nothing but a question.

Pipifix