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.

Form Questions

Form don't redirectback


Go to End
Reply

9 Posts   608 Views

Avatar
feitanx

16 January 2014 at 6:06pm Community Member, 11 Posts

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

16 January 2014 at 8:26pm Forum Moderator, 5511 Posts

What does it to instead?

Avatar
feitanx

17 January 2014 at 2:32pm Community Member, 11 Posts

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

17 January 2014 at 5:29pm Forum Moderator, 5511 Posts

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

Avatar
ajshort

17 January 2014 at 5:38pm Community Member, 244 Posts

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

Avatar
Willr

17 January 2014 at 5:51pm Forum Moderator, 5511 Posts

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

Avatar
feitanx

20 January 2014 at 2:42am Community Member, 11 Posts

I did what you say and here is the screenshot

Attached Files
Avatar
Willr

20 January 2014 at 9:35am Forum Moderator, 5511 Posts

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