# Cakephp 4.x : reset form after submit

**URL:** https://discourse.cakephp.org/t/cakephp-4-x-reset-form-after-submit/7375
**Category:** Need Help
**Created:** [March 2, 2020, 1:08pm UTC](https://discourse.cakephp.org/t/cakephp-4-x-reset-form-after-submit/7375 "2020-03-02T13:08:59Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![general2000vn](https://avatars.discourse-cdn.com/v4/letter/g/a87d85/32.png) [@general2000vn](https://discourse.cakephp.org/u/general2000vn)
#### Post date: [March 2, 2020, 1:09pm UTC](https://discourse.cakephp.org/t/cakephp-4-x-reset-form-after-submit/7375/1 "2020-03-02T13:09:00Z")

</div>

Dear all,

I want to add many records one by one.  
I have an Add form, and want to comeback after Submit, however, the form is full of previous data.  
I have search but did not find solution.  
I tried creating empty entity for the form, but it seems not enough, people say that I have to clear request data. But I dont know how.  
Below is my Add action in Controller

```
public function add($parentID = null)
{
    $kid = $this->Kids->newEmptyEntity();
    
    if ($this->request->is('get')) {
        $pageReferer = $this->referer();
    }
    
    if ($this->request->is('post')) {
        $kid = $this->Kids->patchEntity($kid, $this->request->getData());
        
        $this->loadModel('IcsParents');
        $icsParent = $this->IcsParents->get($this->request->getData('parentID'), ['fields' => ['id', 'family_id']]);
            
            if (is_null($icsParent->family_id)){
                //create family
                $family = $this->Kids->Families->newEmptyEntity();
                $family->consultant_id = $this->Auth->user('id');
                if ($this->Kids->Families->save($family)){
                    $icsParent->family_id = $family->id;
                    $this->IcsParents->save($icsParent);
                    
                    $kid->family_id = $family->id;
                }
                
            } else {
                $kid->family_id = $icsParent->family_id;
            }
            
            
        if ($this->Kids->save($kid)) {    
            $this->Flash->success(__('Đã thêm bé vào Family.'));
            
            if ($this->request->getData('submit') == 1) {
                $kid = $this->Kids->newEmptyEntity();
                $pageReferer = $this->request->getData('pageReferer');
                //$this->request->withoutData('kid'); // I dont know what this statement do, just try
            } else {
                return $this->redirect($this->request->getData('pageReferer'));
            }
            
        } else {
            $this->Flash->error(__('Không thể thêm bé vào Family. Vui lòng kiểm tra các thông tin nhập vào.'));
        }
    }
    $nationalities = $this->Kids->Nationalities->find('list', ['limit' => 200]);
    $eduTypes = $this->Kids->EduTypes->find('list', ['limit' => 200]);
    
    $this->set(compact('kid', 'parentID', 'nationalities', 'eduTypes', 'pageReferer'));
}
```

---

<div class="post-metadata">

### Author: ![MarceliSzpak](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@MarceliSzpak](https://discourse.cakephp.org/u/MarceliSzpak)
#### Post date: [March 2, 2020, 5:28pm UTC](https://discourse.cakephp.org/t/cakephp-4-x-reset-form-after-submit/7375/2 "2020-03-02T17:28:04Z")

</div>

Can you paste controller code ?

---

<div class="post-metadata">

### Author: ![general2000vn](https://avatars.discourse-cdn.com/v4/letter/g/a87d85/32.png) [@general2000vn](https://discourse.cakephp.org/u/general2000vn)
#### Post date: [March 3, 2020, 4:07am UTC](https://discourse.cakephp.org/t/cakephp-4-x-reset-form-after-submit/7375/3 "2020-03-03T04:07:25Z")

</div>

I update the Controller code in my question for your info.

Please help!  
Thank you very much.

---

<div class="post-metadata">

### Author: ![vovo98er](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/vovo98er/32/1721_2.png) [@vovo98er](https://discourse.cakephp.org/u/vovo98er)
#### Post date: [March 19, 2020, 8:01am UTC](https://discourse.cakephp.org/t/cakephp-4-x-reset-form-after-submit/7375/4 "2020-03-19T08:01:12Z")

</div>

You can try redirect to add method after saving data.  
`return $this->redirect(['action' => 'add']);`  
Hi, người Việt Nam.
