StefGuev
StefGuev

Reputation: 649

SilverStripe custom form retrieve values for form fields

I have a problem with my front end admin update page. How can I retrieve values from a SiteTree page and populate it into a custom form? Is the setValue($values) function the only way? If yes, which is the best method to get the page variable?

I am using this:

$evens = Versioned::get_by_stage('PageCalendrierEvenement', 'Stage')->byID($evenID);

I'm getting values from an ID of a draft page. After I get variables and values like that:

$field = new TextField('Titre', 'Titre'); 
$field->setValue($evens->Titre);

or

new TextField('Titre','Titre', $evens->Titre);

Which is the better solution?

Upvotes: 1

Views: 304

Answers (1)

gtufud
gtufud

Reputation: 26

The solution is 2 part:

  1. Use TextField::create($constructor, $args) instead of new (optional, but not doing so is a pet hate of mine).
  2. Set all fields at once: http://api.silverstripe.org/3.1/class-Form.html#_loadDataFrom

Upvotes: 1

Related Questions