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.

Form Questions /

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

Different field types in Create Page form


Go to End


14 Posts   6824 Views

Avatar
Victor

Community Member, 128 Posts

14 March 2009 at 3:53am

I am creating CustomPage.php

and I would like to have certain fields in CMS form to be of "Options" or "RadioButton" or ... type
Is it possible?

Thank you in advance Victor

Avatar
Fuzz10

Community Member, 791 Posts

15 March 2009 at 11:19pm

Avatar
Victor

Community Member, 128 Posts

16 March 2009 at 1:38pm

Edited: 16/03/2009 2:26pm

Thanks! But this documentation is a bit murky: Logically I would expect

Test.php:

<?php

class TestPage extends Page {
   static $db = array(
'Foobar'  => 'Optionset',
   );

   static $has_one = array(
   );

   function getCMSFields() {
      $fields = parent::getCMSFields();
      $fields->addFieldToTab('Root.Content.Main', new OptionsetField(
   $name = "Foobar",
   $title = "FooBar's optionset",
   $source = array(
      "1" => "Option 1",
      "2" => "Option 2",
      "3" => "Option 3",
      "4" => "Option 4",
      "5" => "Option 5"
   ),
   $value = "1"
);, 'Content');


      return $fields;
   }
}

class TestPage_Controller extends Page_Controller {

}
?>


      return $fields;
   }
}

class TestPage_Controller extends Page_Controller {

}
?>

but flushing db results in an error.

Victor

Avatar
Fuzz10

Community Member, 791 Posts

16 March 2009 at 9:31pm

You are confusing DB data field types : http://doc.silverstripe.com/doku.php?id=data-types&s=field%20types

with Form field types :
http://doc.silverstripe.com/doku.php?id=form-field-types

You can use a Text field to store your values.

Avatar
Victor

Community Member, 128 Posts

17 March 2009 at 1:41am

Yes, I looked again and it is clear (unless I am still confused) that

'Foobar'=>'Text'

However simple correction does not work: db flush still returns an error. I need to put somewhere description of the OptionsetField .

Unfortunately I cannot find a sample code (which would also work for checkboxes and radiobuttons) and would greatly appreciate the sample code.

Victor

Avatar
Fuzz10

Community Member, 791 Posts

17 March 2009 at 1:44am

Here is a quick example...

static $db = array(
'Companies' => 'Text',
);

$fields->addFieldToTab('Root.Content.Companies', new OptionsetField('Companies', '', $DataObjectSet->toDropDownMap('id','name')));

Good luck !

Avatar
Victor

Community Member, 128 Posts

17 March 2009 at 4:11am

Thanks, but I am still lost:

If I do simply like:
Test.php

<?php
static $db = array(
      'Companies' => 'Text',
   );
$fields->addFieldToTab('Root.Content.Companies', new OptionsetField('Companies', '', $DataObjectSet->toDropDownMap('id','name')));
?>

db flush does not generate a new page type even if I add

class TestPage_Controller extends Page_Controller {

}

but trying encapsulate the code in

<?php

class TestPage extends Page {

}

bring flush error

Avatar
Fuzz10

Community Member, 791 Posts

17 March 2009 at 4:17am

To work with Silverstripe, you need to be kiinda' comfortable with OO and MVC patterns ...

Also, please take a very good look at the tutorials....

Here is a more useful example....

class Blabla  extends Page {

	public static $db = array(
'Companies' => 'Text'
	);

function getCMSFields() {
 $fields = parent::getCMSFields();	  
     $fields->addFieldToTab('Root.Content.Companies', new OptionsetField('Companies', '', $DataObjectSet->toDropDownMap('id','name')));       

  return $fields;

}

}



class Blabla_Controller extends Page_Controller {
	
	public function init() {
		parent::init();
	}
	

Go to Top