# Validation and redirect

**URL:** <https://discourse.cakephp.org/t/validation-and-redirect/11105>\
**Category:** Need Help\
**Tags:** news, release, help\
**Created:** [March 30, 2023, 2:13pm UTC](https://discourse.cakephp.org/t/validation-and-redirect/11105 "2023-03-30T14:13:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mestizo](https://avatars.discourse-cdn.com/v4/letter/m/c68b51/32.png) [@mestizo](https://discourse.cakephp.org/u/mestizo)\
**Post date:** [March 30, 2023, 2:13pm UTC](https://discourse.cakephp.org/t/validation-and-redirect/11105/1 "2023-03-30T14:13:40Z")

</div>

Good morning guys, I have the following problem and I would like some help:  
In the controller, I perform a double validation, occupying 2 specific fields of the views, it works fine, that is, if the condition is true, it returns an error message, and then I perform a redirect. What’s going on? that the redirect is for the add and it works fine, but when performing the redirect, the form remains empty.  
Is there a way to perform the redirect but without the empty fields? Or do you recommend that I do it in another way?  
I share code snippet to visualize better.

```auto
if ($this->request->is('post')) {
     $delivery = $this->Deliveries->patchEntity($delivery, $this->request->getData());
     $users = $delivery->users_id;
     $usersC = $this->Deliveries->users->find()
            ->select(['id'])
            ->where(['id' => $users]);
     $usersd = $usersC->first();

            if(!$usersd && $delivery->delivered == 0){
                $this->Flash->error("error message");
                return $this->redirect(['controller' => 'Deliveries', 'action' => 'add']);
            }
}

```

Thanks for your help

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [March 30, 2023, 3:16pm UTC](https://discourse.cakephp.org/t/validation-and-redirect/11105/2 "2023-03-30T15:16:57Z")

</div>

You’re redirecting to the same page? Just don’t do that redirect.

---

<div class="post-metadata">

**Author:** ![mestizo](https://avatars.discourse-cdn.com/v4/letter/m/c68b51/32.png) [@mestizo](https://discourse.cakephp.org/u/mestizo)\
**Post date:** [March 30, 2023, 3:37pm UTC](https://discourse.cakephp.org/t/validation-and-redirect/11105/3 "2023-03-30T15:37:37Z")

</div>

Basically, what I want is for the form not to be sent, so even though the condition is true, the form is still sent. That is the reason for the redirect at this time.

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [March 30, 2023, 7:17pm UTC](https://discourse.cakephp.org/t/validation-and-redirect/11105/4 "2023-03-30T19:17:32Z")

</div>

What do you mean you don’t want the form to be sent? The processing you are doing here is only run when you get a `post` request, which means the form has already been sent. If you don’t want to save the data you get from it, just don’t save it. No need to redirect to avoid that.
