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

Form don't redirectback


Go to End


9 Posts   3944 Views

Avatar
feitanx

Community Member, 11 Posts

16 January 2014 at 6:06pm

class AddEmail_Controller extends Page_Controller {
private static $allowed_actions = array(
'AddEmail'
);

public function AddEmail() {
$form = new Form(
$this, // controller
"AddEmail", // form name
new FieldList( // fields
TextField::create("AgentName"),
TextField::create("Address"),
EmailField::create("Email"),
TextField::create("Company"),
NumericField::create("Phone"),
DropdownField::create("Dropdown",
"Location",
array(
'Sydney',
'Canbera',
'Perth',
'Melbourne',
'Malaysia',
'HongKong'
)),
DropdownField::create("Dropdown2",
"Location",
array(
'Australia',
'China',
'Malaysia',
'HongKong'
))),
new FieldList( // actions
new FormAction('doAddEmail', 'ubmit')
)

);

return $form->renderWith('AddEmailForm');

}
public function doAddEmail($data, $form) {
return $this->redirectBack();
}

}

When I click the submit button, it doesn't redirect back to the form as its supposed to do.

Avatar
Willr

Forum Moderator, 5523 Posts

16 January 2014 at 8:26pm

What does it to instead?

Avatar
feitanx

Community Member, 11 Posts

17 January 2014 at 2:32pm

It is supposed to go back to the original form. But it returns a incomplete form page unlike the original somewhat change the URI.

Avatar
Willr

Forum Moderator, 5523 Posts

17 January 2014 at 5:29pm

Can you post a screenshot of what the incomplete result looks like?

Avatar
ajshort

Community Member, 244 Posts

17 January 2014 at 5:38pm

"return $form->renderWith('AddEmailForm');" should be "return $form" - you need to return the actual form object.

Avatar
Willr

Forum Moderator, 5523 Posts

17 January 2014 at 5:51pm

And to further what ajshort said, if you want to provide a custom template use $form->setTemplate() in that case.

Avatar
feitanx

Community Member, 11 Posts

20 January 2014 at 2:42am

I did what you say and here is the screenshot

Attached Files
Avatar
Willr

Forum Moderator, 5523 Posts

20 January 2014 at 9:35am

This error message is the CSRF_FAILED_MESSAGE warning. If you have a custom form template make sure it contains the SecurityID field, or if the form is non destructive you can disable the CSRF token by calling $form->disableSecurityToken()

Go to Top