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.

Archive

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

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

Form submision without redirect


Reply

5 Posts   1803 Views

Avatar
danielbenedykt

16 October 2008 at 5:21am Community Member, 9 Posts

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

Avatar
Willr

16 October 2008 at 6:24pm Forum Moderator, 5511 Posts

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

Avatar
danielbenedykt

17 October 2008 at 12:56am Community Member, 9 Posts

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

Avatar
Willr

17 October 2008 at 6:31pm Forum Moderator, 5511 Posts

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']

Avatar
danielbenedykt

18 October 2008 at 1:11am Community Member, 9 Posts

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