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.

Installing SilverStripe /

Getting SilverStripe up and running on your computer and on your web server.

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

Search Form: "Server error Sorry, there was a problem with handling your request."


Go to End


11 Posts   8756 Views

Avatar
smith256

Community Member, 2 Posts

4 April 2016 at 11:05pm

use CheckboxSetField to manage the many_many relation.

this will not allow creating Ingredients on the fly, it will only give you check boxes that you can tick to link the items.

public function FragranceAddForm() {
$fragrances_field = new CheckboxSetField('Ingredients', 'Ingredient', Ingredient::get()->map());

$fields = new FieldList(
new TextField('Name', 'Fragrance Name'),
new TextareaField('Description', 'Fragrance Description'),
$fragrances_field
);

$actions = new FieldList(
new FormAction('doFragranceAdd', 'Add Fragrance')
);

$validator = new RequiredFields('Name', 'Description');

return new Form($this, __FUNCTION__, $fields, $actions, $validator);
}

public function doFragranceAdd($data, $form) {
$submission = new Fragrance();
$form->saveInto($submission);
$submission->write();

return $this->redirectBack();
}

https://in.linkedin.com/in/harsimratkaurbadal

Avatar
smith256

Community Member, 2 Posts

4 April 2016 at 11:06pm

Edited: 04/04/2016 11:11pm

use CheckboxSetField to manage the many_many relation.

this will not allow creating Ingredients on the fly, it will only give you check boxes that you can tick to link the items.

public function FragranceAddForm() {
$fragrances_field = new CheckboxSetField('Ingredients', 'Ingredient', Ingredient::get()->map());

$fields = new FieldList(
new TextField('Name', 'Fragrance Name'),
new TextareaField('Description', 'Fragrance Description'),
$fragrances_field
);

$actions = new FieldList(
new FormAction('doFragranceAdd', 'Add Fragrance')
);

$validator = new RequiredFields('Name', 'Description');

return new Form($this, __FUNCTION__, $fields, $actions, $validator);
}

public function doFragranceAdd($data, $form) {
$submission = new Fragrance();
$form->saveInto($submission);
$submission->write();

return $this->redirectBack();
}

Harsimrat Kaur Badal

Avatar
meichan

Community Member, 1 Post

5 April 2016 at 1:47am

Edited: 05/04/2016 1:48am

Go to Top