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.

Form Questions /

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

Allowed Actions Mistery


Go to End


1290 Views

Avatar
Mia

Community Member, 8 Posts

6 September 2014 at 1:04am

Edited: 06/09/2014 1:06am

Hi,

I have recently come across a very weird behaviour. I looked at http://doc.silverstripe.org/framework/en/topics/forms and a few other sources and it is very clear that form actions should not specifically be put in the allowed_actions array, as adding the form will automatically give the action permission.

When you return a form to a page as in "Form"=>$this->CustomForm(), you only have to add the CustomForm in the allowed_actions array, and not the action. But when you call $CustomForm from a template, you require both the CustomForm as well as the action to be in the allowed_actions. Why is this?

//returning a form

//class initlalization
$allowed_actions = array(
    "CustomForm",
    "something
);

function CustomForm(){
//some form here
}

function something(){
    return array("Form"=>$this->CustomForm());
}

//in the Page_something.ss
$Form

//calling a form

//class initlalization
$allowed_actions = array(
    "CustomForm",
    "doSubmitCustom",
    "something
);

function CustomForm(){
//some form here
}

//in the Page.ss
$CustomForm

I can only assume that calling the Form from the template would result in the same behaviour as calling an action directly through an href link, in which case the action is required to be in the allowed actions, but why do it with the form if a post is being done anyways?