<p>Maybe not the prettiest URL, but I think the simplest solution would be to redirect to something like:</p>

<pre><code>http://web.dev/success?id=ch_5GW2RFTNvW8qeR
</code></pre>

CC BY-SA 3.0
2015-02-21T00:48:19.400Z
2015-02-21T00:48:19.400Z
Brad Bell
<p>I am creating a plugin where the user is submitting data to a controller.</p>

<p>With a successful saving of the data in the controller/service I want to honour the standardised redirect param:</p>

<p><code>&lt;input type="hidden" name="redirect" value="success/{stripeId}"/&gt;</code></p>

<p>The stripeId is a property of the PaymentModel $payment being passed to the redirectToPostedUrl param:</p>

<p><code>$this-&gt;redirectToPostedUrl($payment);</code></p>

<p>This works in that when the person is redirected the person is brought to page desired with url like this: </p>

<p><code>http://web.dev/success/ch_5GW2RFTNvW8qeR</code></p>

<p>The problem is that craft cannot find the success template and the success page does not show since it is trying to find a template a <code>success/</code> directory called <code>ch_5GW2RFTNvW8qeR.html</code></p>

<p>2 Solutions I have found:</p>

<p><strong>Option 1)</strong> My plugin users need to set up a route manually in the control panel to allow this to resolve correctly (and have full control over where the success page is and what the url looks like):</p>

<p><img src="https://i.sstatic.net/OxkVk.png" alt="image of manual route setup"></p>

<p><strong>Option 2)</strong> The other option is that I use the Plugin hook <code>registerSiteRoutes</code> to register a front end route to that template. The obvious problem with that is I either need to make that hard coded, or user configurable (pain).</p>

<p>Since I would obviously need to make it user configurable, it kinda defeats the purpose of the user of the plugin being able to decide the <code>name="redirect" value="success/{stripeId}"</code> in the first place. I would imagine I would have to come up with my own redirection/routing config and logic. I understand this is not a problem in the control panel actions since I know what I want my urls to be, but as a plugin developer I want to give flexibility to users of my plugin to choose their front-end urls.</p>

<p>Any thoughts? I am leaning towards having to put into the documentation of my plugin that they need to do option 1 above, but still think its not optimal.</p>

<p>Edit: 
Just had another idea. <strong>Option 3)</strong> Since I will be giving my users demo templates for the front end forms on installation - should I possibly create a route in the <code>craft_routes</code> table for  the user? That way on first install everything should work without needing to manually set up a bunch of routes manually to match my demo templates.</p>

CC BY-SA 3.0
2014-12-05T16:54:31.677Z
Couldn't you also just redirect to `http://web.dev/success?id=ch_5GW2RFTNvW8qeR`
Brad Bell
CC BY-SA 3.0
2015-01-15T14:54:30.050Z
yes indeed Brad, will consider that the best option so far. Not as aesthetically pleasing but works!!! You the man, have a drink of water.
Luke Holder
<plugin-development><routes>
redirectToPostedUrl with object (Model) passed to it and keep template resolving
# redirectToPostedUrl with object (Model) passed to it and keep template resolving

(Asked by: username_0 on 2014-12-05)

I am creating a plugin where the user is submitting data to a controller.

With a successful saving of the data in the controller/service I want to honour the standardised redirect param:

The stripeId is a property of the PaymentModel $payment being passed to the redirectToPostedUrl param:

`$this->redirectToPostedUrl($payment);`

This works in that when the person is redirected the person is brought to page desired with url like this:

`http://web.dev/success/ch_5GW2RFTNvW8qeR`

The problem is that craft cannot find the success template and the success page does not show since it is trying to find a template a `success/` directory called `ch_5GW2RFTNvW8qeR.html`

2 Solutions I have found:

**Option 1)** My plugin users need to set up a route manually in the control panel to allow this to resolve correctly (and have full control over where the success page is and what the url looks like):

![image of manual route setup](https://i.sstatic.net/OxkVk.png)

**Option 2)** The other option is that I use the Plugin hook `registerSiteRoutes` to register a front end route to that template. The obvious problem with that is I either need to make that hard coded, or user configurable (pain).

Since I would obviously need to make it user configurable, it kinda defeats the purpose of the user of the plugin being able to decide the `name="redirect" value="success/{stripeId}"` in the first place. I would imagine I would have to come up with my own redirection/routing config and logic. I understand this is not a problem in the control panel actions since I know what I want my urls to be, but as a plugin developer I want to give flexibility to users of my plugin to choose their front-end urls.

Any thoughts? I am leaning towards having to put into the documentation of my plugin that they need to do option 1 above, but still think its not optimal.

Edit:
Just had another idea. **Option 3)** Since I will be giving my users demo templates for the front end forms on installation - should I possibly create a route in the `craft_routes` table for the user? That way on first install everything should work without needing to manually set up a bunch of routes manually to match my demo templates.

**Tags:** plugin-development, routes

> **Comments:**
> **username_1**: Couldn't you also just redirect to `http://web.dev/success?id=ch_5GW2RFTNvW8qeR`  
> **username_0**: yes indeed Brad, will consider that the best option so far. Not as aesthetically pleasing but works!!! You the man, have a drink of water.  

---

## 1 answers

### Answer by username_1 on 2015-02-21. Score: 1 | Accepted answer

Maybe not the prettiest URL, but I think the simplest solution would be to redirect to something like:
http://web.dev/success?id=ch_5GW2RFTNvW8qeR


---

