Page refresh and form Re-submission

Hi all,

How can I prevent form values from being re-submitted on page refresh?

Thanks in advance!

The data will be submitted just because they are in a form, there is no way to avoid.

You can avoid to process this data, for example by cleanin the model before passing it to the view, or by mark the field you don’t want to resend as ‘unsafe’ by deleting any validator on it.

Note that marking as unsafe a filed will avoid data to be massively assigned, so in your model there will always be the previous value.

Not sure you can do anything about this, other than to put the data in a session and make the controller action redirect to another view.

Yes, is just what I have made… ;)

OrderController:





    public function actionOrder() {

        $model = $this->loadModel();

        if (isset($_POST['ProductList'])) {

            $_SESSION['ProductList'] = $_POST['ProductList'];

            $this->redirect(array('purchase/start','id' => $model->id), false);

        } else {

            $this->render('view', array(

                'model' => $model,

            ));

        }

    }



PurchaseController:




public function actionStart() {

        if (isset($_SESSION["TicketList"])) {

            $Purchase = new Purchase();

            /*

	     * ...

             * ...	     

             */

        }

        $this->render('start', array(

            'model' => $_SESSION["Purchase"],

            'summary' => $_SESSION["PurchaseSummary"],

        ));

    }



Thanks!