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.

Data Model Questions /

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

Loading data into form : BootstrapForm::loadDataFrom()


Go to End


2 Posts   2091 Views

Avatar
Optic Blaze

Community Member, 190 Posts

8 October 2013 at 12:04pm

I am trying to load data into a form. I am using the bootstrap-forms module from Uncle Cheese. As i understand it i would normally call $form->loadDataFrom(Customer::get()->byID(4)) but the bootstrap module structures the form differently.

//CREATE CUSTOMER FORM
public function CustomerForm() {
return BootstrapForm::create(

$this,
"CustomerForm",
FieldList::create(
TextField::create("Name","Name")
TextField::create("Surname","Surname"),

FieldList::create(
FormAction::create("AddCustomer","Add customer")
->setStyle("success")
),
RequiredFields::create(array("Name","Surname","Tel1", "Address")),

/// I think the load data method should go here but i keep getting errors
BootstrapForm::loadDataFrom(Customer::get()->byID(4))

)
}

Any help will be appreciated

Avatar
Optic Blaze

Community Member, 190 Posts

11 October 2013 at 10:38am

GOT IT!!!!!

/CREATE CUSTOMER FORM
public function CustomerForm() {
return BootstrapForm::create(

$this,
"CustomerForm",
FieldList::create(
TextField::create("Name","Name")
TextField::create("Surname","Surname"),

FieldList::create(
FormAction::create("AddCustomer","Add customer")
->setStyle("success")
),
RequiredFields::create(array("Name","Surname","Tel1", "Address")),
)
->loadDataFrom(Customer::get()->byID(4));
}