tags:

views:

19

answers:

1

I have a showSuccess page that requires some get variables, and on that page is a form. When the form submits to executeCreate() and there is an error, it calls the function setTemplate('show') and returns back to showSuccess. However, the get variables are missing.

How do I keep the url the same?

A: 

You can get your GET variables from the sfWebRequest object - something like the following should work):

public function executeCreate(sfWebRequest $request)
{
  $getVars = $request->getGetParameters();
  $qryString = http_build_query($getVars);

  // ...some form creation and binding

  if (!$form->isValid())
  {
    $this->redirect("module/show?" . $qryString);
  }
}

You probably also need these in your form in the template. Use the relevant parts of the above code in your show action, set them to the view as you would any other variable and use them in the form action parameter:

<form method="post" action="<?php echo url_for("module/create?" . $qryString); ?>">
</form>
richsage
although this correctly keeps my url, by using the redirect method, it loses track of the form that was not valid, so the entered values and error messages are lost
in that case, change the `if` structure to `if ($form->isValid()) { ... }` and redirect away if the form was successful. That way your action will still display the form values etc if the validation fails. Let me know if you want an example :-)
richsage