Jump to:

23483 Posts in 18965 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Extending a Page - Textfields in BE dont save

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

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

Page: 1
Go to End
Author Topic: 609 Views
  • Pipifix
    Avatar
    Community Member
    54 Posts

    Extending a Page - Textfields in BE dont save Link to this post

    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!?

  • Pipifix
    Avatar
    Community Member
    54 Posts

    Re: Extending a Page - Textfields in BE dont save Link to this post

    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

    609 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.