Skip to main content
added 4 characters in body
Source Link
Brad Bell
  • 67.6k
  • 6
  • 75
  • 145

I currently have a form that is being displayed to the user via a custom route.

The form submits to a controller. The first thing the controller does is populate a custom model and validates it.

If the model fails validation, I want to skip the rest of the controller and pass the model back to the form. What is the best way to do this? I tried using craft()->urlManager->setRouteVariables and a $this->redirect$this->redirect, but the route variable didn't seem to come through, which I imagine is because setRouteVariablessetRouteVariables isn't supposed to be used like that.

I currently have a form that is being displayed to the user via a custom route.

The form submits to a controller. The first thing the controller does is populate a custom model and validates it.

If the model fails validation, I want to skip the rest of the controller and pass the model back to the form. What is the best way to do this? I tried using craft()->urlManager->setRouteVariables and a $this->redirect, but the route variable didn't seem to come through, which I imagine is because setRouteVariables isn't supposed to be used like that.

I currently have a form that is being displayed to the user via a custom route.

The form submits to a controller. The first thing the controller does is populate a custom model and validates it.

If the model fails validation, I want to skip the rest of the controller and pass the model back to the form. What is the best way to do this? I tried using craft()->urlManager->setRouteVariables and a $this->redirect, but the route variable didn't seem to come through, which I imagine is because setRouteVariables isn't supposed to be used like that.

Source Link
John O
  • 391
  • 1
  • 9

Passing data back to form on invalid submission

I currently have a form that is being displayed to the user via a custom route.

The form submits to a controller. The first thing the controller does is populate a custom model and validates it.

If the model fails validation, I want to skip the rest of the controller and pass the model back to the form. What is the best way to do this? I tried using craft()->urlManager->setRouteVariables and a $this->redirect, but the route variable didn't seem to come through, which I imagine is because setRouteVariables isn't supposed to be used like that.