# How to redirect the same page

**URL:** <https://discourse.slimframework.com/t/how-to-redirect-the-same-page/902>\
**Category:** Questions\
**Created:** [November 14, 2016, 9:20pm UTC](https://discourse.slimframework.com/t/how-to-redirect-the-same-page/902 "2016-11-14T21:20:21Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![haizone](https://avatars.discourse-cdn.com/v4/letter/h/ad7895/32.png) [@haizone](https://discourse.slimframework.com/u/haizone)\
**Post date:** [November 14, 2016, 9:20pm UTC](https://discourse.slimframework.com/t/how-to-redirect-the-same-page/902/1 "2016-11-14T21:20:21Z")

</div>

hi  
i have a functio to send a mail from the site with filds

how i do that when i send the msg mail i stay in the same page and not go to other page?

---

<div class="post-metadata">

**Author:** ![tflight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/tflight/32/1205_2.png) [@tflight](https://discourse.slimframework.com/u/tflight)\
**Post date:** [November 14, 2016, 9:55pm UTC](https://discourse.slimframework.com/t/how-to-redirect-the-same-page/902/2 "2016-11-14T21:55:14Z")

</div>

```php
return $response->withRedirect('http://example.com');

```

Depending what you might be using for a view layer or template you can likely specify the location by name. If you are using Slim-Twig:

```php
return $response->withRedirect($this->router->pathFor('routeName'));

```

---

<div class="post-metadata">

**Author:** ![haizone](https://avatars.discourse-cdn.com/v4/letter/h/ad7895/32.png) [@haizone](https://discourse.slimframework.com/u/haizone)\
**Post date:** [November 15, 2016, 6:44am UTC](https://discourse.slimframework.com/t/how-to-redirect-the-same-page/902/3 "2016-11-15T06:44:14Z")

</div>

thank but i dont know what a conroller send th form

again:

i have thr same form in a 4 pages  
when i send the form i return to other routeName  
but i when to stay in the same page and not Redirect to other

---

<div class="post-metadata">

**Author:** ![tflight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/tflight/32/1205_2.png) [@tflight](https://discourse.slimframework.com/u/tflight)\
**Post date:** [November 15, 2016, 12:27pm UTC](https://discourse.slimframework.com/t/how-to-redirect-the-same-page/902/4 "2016-11-15T12:27:01Z")

</div>

Do you want to stay on the same page by using an Ajax call? Otherwise you would just return the response with the page you would like.

---

<div class="post-metadata">

**Author:** ![haizone](https://avatars.discourse-cdn.com/v4/letter/h/ad7895/32.png) [@haizone](https://discourse.slimframework.com/u/haizone)\
**Post date:** [November 15, 2016, 12:58pm UTC](https://discourse.slimframework.com/t/how-to-redirect-the-same-page/902/5 "2016-11-15T12:58:42Z")

</div>

u can help me and show me exmple  
plz with a form with name and phone to send to controller

---

<div class="post-metadata">

**Author:** ![tflight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/tflight/32/1205_2.png) [@tflight](https://discourse.slimframework.com/u/tflight)\
**Post date:** [November 15, 2016, 2:56pm UTC](https://discourse.slimframework.com/t/how-to-redirect-the-same-page/902/6 "2016-11-15T14:56:43Z")

</div>

I’m not sure I understand what you are trying to accomplish. Here is a ( **not very secure** ) example of a controller method that would accept an email and phone number from a form, send an email, and then send the user back to a specific page.

```php
    public function mailPhoneAction($request, $response, $args)
    {
        $emailAddress = $request->getParsedBodyParam('email_address');
        $phoneNumber = $request->getParsedBodyParam('phone_number');
        mail($emailAddress, 'Your Phone Number', "Your phone number is $phoneNumber");
        return $response->withRedirect('http://example.com');
    }

```

---

<div class="post-metadata">

**Author:** ![haizone](https://avatars.discourse-cdn.com/v4/letter/h/ad7895/32.png) [@haizone](https://discourse.slimframework.com/u/haizone)\
**Post date:** [November 15, 2016, 3:12pm UTC](https://discourse.slimframework.com/t/how-to-redirect-the-same-page/902/7 "2016-11-15T15:12:04Z")

</div>

that i know  
but how i do with ajax??  
to stay at the same page after i do a submit ?

---

<div class="post-metadata">

**Author:** ![tflight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/tflight/32/1205_2.png) [@tflight](https://discourse.slimframework.com/u/tflight)\
**Post date:** [November 15, 2016, 6:50pm UTC](https://discourse.slimframework.com/t/how-to-redirect-the-same-page/902/8 "2016-11-15T18:50:34Z")

</div>

I haven’t used Slim with Ajax requests. I don’t believe there is anything really peculiar versus other packages, but hopefully someone else will chime in.
