SilverCart Forum
We moderate this Forum and we're here to help. Have you already run a forum search to check if your problem has already been solved?
You can help us helping you by providing detailed error messages, screenshots and logfile entries.
Page: 1 | ||
Topic Form action won't get triggered in ModelAdmin sidebar | 2380 Views |
Form action won't get triggered in ModelAdmin sidebar
19 December 2011 at 11:58amHi guys,
i want to add a new search form in the silverstripe backend for silvercart products to display specific products after a form submit. I saw that you add a form to import product pictures in SilvercartProduct_CollectionController. So if i understand this correct i'll need to decorate the SilvercartProduct_CollectionController to maintain upgradeability of silvercart, right?
I tried this and i got the form displayed below the "ImportImagesForm" but it seems that the action won't be triggered when i press the submit button.
My form action looks like this:
$action = new FieldSet(new FormAction('searchproducts', 'Show required products'));
I also wrote a function called "searchproducts" in this decorator, but it seems that i can't access it from the form after a submit. At least "searchproducts" won't get called.
Maybe you could help me to get this function triggered.
Bye
Re: Form action won't get triggered in ModelAdmin sidebar
20 December 2011 at 8:40pmHi Jethro,
we talked about your issue today. Patrick will come up with a solution tomorrow after he did some testing.
Cheers
Ramon
Re: Form action won't get triggered in ModelAdmin sidebar
21 December 2011 at 2:35pm Last edited: 21 December 2011 2:37pmHi Jethro,
sorry for the delayed anwser. I looked into your problem yesterday and found a solution for you.
Your approach is correct. You need to decorate SilvercartProduct_CollectionController.
We have implemented a method in SilvercartProduct_CollectionController called "customFormAction". This function provides you the ability to extend it in your decorator via "updateCustomFormAction". This function should look like this:
/**
* calls form action ( $data['action'] ) to parse results
*
* @param array $data The sent data
* @param Form $form The connected form
* @param SS_HTTP_Request $request The request object
* @param SS_HTTPResponse $output templated result
*
* @return void
*
* @author Patrick Schneider <pschneider@pixeltricks.de>
* @since 20.12.2011
*/
public function updateCustomFormAction($data, $form, $request, &$output) {
if (method_exists($this, $data['action'])) {
$this->$data['action']($data, $form, $request, $output);
}
}
updateCustomFormAction will call your defined form action. We had some trouble here and advise to add a new HiddenField to your form do define your action:
new HiddenField(
'action',
'',
'searchproducts')
After a submit the functions should get called like this:
1. SilvercartProductCollection_Controller: customFormAction()
2. Decorator: updateCustomFormAction()
3. Decorator: your defined action from HiddenField (e.g. searchproducts)
After this your function "searchproducts" should get called. Note that you need to reference the parameter $output:
public function searchproducts($data, $form, $request, &$output) {}
You can manipulate your result and render it in a ResultForm. Finally $output needs to be a SS_HTTPResponse object. You can look at the SilverStripe search form to get a example on how to return your result. It's located in the "ModelAdmin.php" file which provides a function called "search" (SilverStripe 2.4.5/2.4.6 Line 650)
I hope that i could help you with your problem. Please let me know if you have any further questions.
Ciao
Patrick