Jump to:

2002 Posts in 1422 Topics by 616 members

Form Questions

SilverStripe Forums » Form Questions » Form don't redirectback

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

Page: 1 2
Go to End
Author Topic: 509 Views
  • feitanx
    Avatar
    Community Member
    11 Posts

    Form don't redirectback Link to this post

    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.

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Form don't redirectback Link to this post

    What does it to instead?

  • feitanx
    Avatar
    Community Member
    11 Posts

    Re: Form don't redirectback Link to this post

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

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Form don't redirectback Link to this post

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

  • ajshort
    Avatar
    Community Member
    244 Posts

    Re: Form don't redirectback Link to this post

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

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Form don't redirectback Link to this post

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

  • feitanx
    Avatar
    Community Member
    11 Posts

    Re: Form don't redirectback Link to this post

    I did what you say and here is the screenshot

    Attached Files
  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Form don't redirectback Link to this post

    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()

    509 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.