[solved] Displaying a confirmation page

Basically I want to display a confirmation page when the model data is valid and the record has been saved. The problem I have is that I don’t wish to expose any id/model data in the URL. So for example the form is at URL:

/localhost/quote

This renders views/site/quote.php

My confirmation page is views/site/thanks.php

So the URL of the confirmation should ideally be (/localhost/quote), or have its own URL/action (/localhost/thanks)

If I render the confirmation in the same action, then the form data can be re-submitted by reloading the page. And I prefer not to use sessions either.

If I render the confirmation in its own action, then how can I pass in model data without using GET variables or sessions?

So what options do I have?

You could redirect to a thank-you action ?

Take a look at how works flash message.

Basically they save in the user state the message and display in the next page. You can simply redirect to a tank-you action, and save message and return-url in the state.

I use different approaches to get the same result as you want but I will tell you one, you brainstorm a bit and you will see that you can actually develop better things.

I hide the information of the model in base64 encripted strings, saved in hidden fields as asp.net does to maintain the state of their fields. So, you call the hidden field the way you want and then have a chunk of silly data attached in front or at the back of the information you wish to hide, then, on form submission, you check the hidden field against the data at the server, get the decoded data and query the DB.

The problem is that the length of the data you plug at the front or at the back of the data you wish to encode must be always of same size if you don’t wish to work with SESSIONS but it is a good trick.

Hmm I didn’t think of that! So basically I create a new action (actionThanks) and then I need to check if there is a flash message present - if yes then render the thanks page - if no then redirect to actionQuote.


public function actionThanks()

{

	if(Yii::app()->user->hasFlash('success'))

	{

		$this->render('thanks');

	}

	else

	{

		$this->redirect(array('quote'));

	}

}

The problem there is that when I make a call to hasFlash() in my controller action, this then deletes the flash message - so how can I pass on the flash message to my view file?

Bump

Why you think so?

You can save the value in a variable:




public function actionThanks()

{

        if($message= Yii::app()->user->getFlash('success'))

        {

                $this->render('thanks', array('message'=>$message));

        }

        else

        {

                $this->redirect(array('quote'));

        }

}



Anyway is really strange this behavior, flash messages are deleted on reload of page.

Are you sure that you have the flash setted in the controller?