23377 Posts in 18296 Topics by 2867 members
|Go to End|
15 June 2012 at 1:29am
So I've got a few functions, and I'm using DataObjectDecorator to make them available for all pages, but also certain DataObjects.
The functions contain a Form, and it's action method.
I have the decorator working, as the form is being displayed fine on a page, however, the problems start when I try to submit the form, I'm getting the following error:
[User Error] Uncaught Exception: Object->__call(): the method 'checkaccessaction' does not exist on 'OfferPage
OfferPage is my page type, and the method "checkaccessaction" isn't one of mine, so what's going on?
Here is my decorator code: http://spdr.me/lnTx
15 June 2012 at 7:06am
checkaccessaction() is a SilverStripe method that checks if a given action is allowed on a given controller. When your form is posted, you provide a form action in the url, and SilverStripe is now checking that for its validity. Any controller should have access to this function since it is defined in the base Controler class.
So it looks the controller that you're using isn't really a controller. I've never really created form functionality using a decorator, but as you'd normally create the form from within the Page_Controller, I think you might want to decorate the Page_Controller instead of the Page class. In that case you should use the Extension class instead of the DataObjectDecorator, since the page_Controller isn't a DataObject...
Hope this helps...
15 June 2012 at 7:23am
Ah, that makes sense, I'll give this a go tomorrow. Thanks martimiz, I'll let you know how I get on!
16 June 2012 at 1:31am
Ok, that's working great now on Pages, but still got a problem with it on DataObjects:
For example I have my videos page at /videos and the URL for a video is /videos/view/34 (where 34 is the video ID). Now when I submit the comment form for a video, it's looking for the comment form method at /videos/view/34/CommentForm where it obviously doesn't exist as it's already calling the view action with an ID.
Any ideas how I can work around this?
16 June 2012 at 4:53am
Afaik that souldn't really happen. Even though you add the /view/23/ bit as $Action/$ID to the URL, SilverStripe should still recognize the original URLSegment, and submit to /videos/CommentForm. I've a similar situation here (the only difference being that my form is generated by a shortcode) and that works as it's supposed to.
I'm using a simple Director::redirectBack(); at the end of the submission handler - and that takes me right back to the original DataObject on the page...
So I don't know what's happening in your case - unless you made some other changes that could influence the way links are created?
16 June 2012 at 10:45pm
Ah, so in that case it's probably because I am putting the form inside my dataobject (video) control, in the template, rather than directly on the page. When I move it outside of the control, it correctly submits to /videos/CommentForm.
However, as this is a comment form, it needs to know the ID and Class of the current DataObject or Page within the form action. And when the CommentForm is placed outside of the dataobject control on the page, it is unable to obtain this information. What is the best way to deal with this?
Many thanks again!
17 June 2012 at 12:47am
The page controller knows the id of the video from the url. You should be able to get it (using $this->urlParams['ID'] if i recall it correctly) and send it to your template using some function like GetVideoID(), to create a hidden field...
17 June 2012 at 6:21am
Thanks so much martimiz, I got it all working!
|Go to Top|