Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Form submision without redirect

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 1769 Views
  • danielbenedykt
    Avatar
    Community Member
    9 Posts

    Form submision without redirect Link to this post

    Hi,

    I did a form using code, and the form is submitted on the onSubmit method.
    All the examples I saw have a Director::Redirect on that method after the data is saved.
    The issue is that if the user clicks the back button on the browser, the form is submitted again, instead if going to the form itself.

    Is there any solution to this? Is there a way to display information on the page after the onSubmit method manages the data without redirecting?

    Thanks

    Daniel

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: Form submision without redirect Link to this post

    can't you just remove the Director::redirect() code. If this your custom form or a user defined form

  • danielbenedykt
    Avatar
    Community Member
    9 Posts

    Re: Form submision without redirect Link to this post

    Hi Will,

    Thanks for the quick response.
    Its a Custom Form

    Here is a psudocode of my code. I hope this is clear.
    This way it works perfect, but I am looking for a way to do the same without the redirect.

    Maybe I am doing something wrong, but if I dont put the redirect on the "doRequestDemo", I get a white screen.

    Thanks

    Daniel

    ----------------------------------------------------------------------------

    class RequestDemo_Controller
    {

    function RequestDemoForm() {
    //method to show the form
    //this method is called in the .ss to show the form
    $fields = new FieldSet(
                new TextField('city','City'),
                new TextField('county','County'));
    $actions = new FieldSet(
                new FormAction('doRequestDemo', 'Submit')
                );
    return new Form($this, 'RequestDemoForm', $fields, $actions, $validator);

    }

    function doRequestDemo($data, $form) {
    //method executed when form is submitted
    //do some processing and SQL query
    //save the information in session.
    Director::redirect(Director::currentURLSegment() . "?p=2");
    //if I dont put the Director::redirect, I get a white screen, nothing happens, so I redirected to the same page with p=2
    }

    function showResult()
    {
    //function to show the result on the .ss page
    if (p==2)
    {
    //show the result from the session.
    }
    }

    }//end class

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: Form submision without redirect Link to this post

    yes you would get a blank screen as after you 'doRequestDemo' you dont tell it to do anything. You can do what you have done eg redirect to /page/?p=2 then you would access p like $_GET['p']

  • danielbenedykt
    Avatar
    Community Member
    9 Posts

    Re: Form submision without redirect Link to this post

    Hi Will,

    Thanks for your help.
    So basically if the redirect is needed, so if the user clicks the back button, he will not see the form. He will see the re-post of the form.

    Thanks

    Daniel

    1769 Views
Page: 1
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.