# Cake 3.7: Adding multiple records, one at a time

**URL:** <https://discourse.cakephp.org/t/cake-3-7-adding-multiple-records-one-at-a-time/5788>\
**Category:** Need Help\
**Created:** [March 14, 2019, 2:07pm UTC](https://discourse.cakephp.org/t/cake-3-7-adding-multiple-records-one-at-a-time/5788 "2019-03-14T14:07:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![efanzini](https://avatars.discourse-cdn.com/v4/letter/e/2acd7d/32.png) [@efanzini](https://discourse.cakephp.org/u/efanzini)\
**Post date:** [March 14, 2019, 2:07pm UTC](https://discourse.cakephp.org/t/cake-3-7-adding-multiple-records-one-at-a-time/5788/1 "2019-03-14T14:07:48Z")

</div>

Hi all.  
I have one of my customers wich regularly receives deliveries of fabric rolls and needs to keep track of them.  
Each delivery contains N rolls, all from the same manufacturer and with the same height, length and fabric type.  
Each roll has its own serial number, printed on a label.

My first thought was to design a form where the user enters the common properties and then all the serial numbers, one by row.  
Unfortunately this idea has been discarded because the customer’s warehouse chief wants to add the rolls one by one (basically he wants a visual and acoustic confirmation after every roll has been added successfully).

So i tried to design an action where the form gets pre-filled with the same data as the latest successfull save.

This is what i came up with:

> public function addMulti()  
> {  
> $roll = $this-\>Rolls-\>newEntity();
> 
> ```
> if ($this->request->is(['post', 'put'])) {
> $roll = $this->Rolls->patchEntity($roll, $this->request->getData());
> if ($this->Rolls->save($roll)) {
> $this->Flash->success(__('Roll successfully added'));
> $this->id = $roll->serial_number = null;
> $roll->clear();
> } else {
> $this->Flash->error(__('Unable to add roll'));
> }
> }
> 
> $this->set('roll', $roll);
> $this->set('manufacturers', $this->Rolls->Manufacturers->find('list'));
> $this->set('fabrics', $this->Rolls->Fabrics->find('list'));
> 
> ```
> 
> }

And here’s the ‘add\_multi’ template

> echo $this-\>Form-\>create();
> 
> echo $this-\>Form-\>control(‘serial\_number’, [‘autofocus’ =\> ‘autofocus’]);
> 
> echo $this-\>Form-\>control(‘manufacturer\_id’, [  
> ‘options’ =\> $manufacturers  
> ]);
> 
> echo $this-\>Form-\>control(‘fabric\_id’, [  
> ‘options’ =\> $fabrics  
> ]);
> 
> echo $this-\>Form-\>control(‘height’);  
> echo $this-\>Form-\>control(‘length’);
> 
> echo $this-\>Form-\>submit();  
> echo $this-\>Form-\>end();

But it’s not working.  
The ‘serial\_number’ form control keeps the submitted value and i’m not able to understand why.  
I even tried messing up with the $\_POST variable and request-\>data but so far i’ve not been able to acheive what my customer wants.

Am i missing something?

Sorry for the long post and for the bad english.

Thank you.

---

<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 14, 2019, 3:38pm UTC](https://discourse.cakephp.org/t/cake-3-7-adding-multiple-records-one-at-a-time/5788/2 "2019-03-14T15:38:18Z")

</div>

Try

```
echo $this->Form->create($roll);

```

Without providing an entity there, it will look to what was posted, and it might be looking somewhere that you didn’t reset in your attempts.

---

<div class="post-metadata">

**Author:** ![efanzini](https://avatars.discourse-cdn.com/v4/letter/e/2acd7d/32.png) [@efanzini](https://discourse.cakephp.org/u/efanzini)\
**Post date:** [March 15, 2019, 7:29am UTC](https://discourse.cakephp.org/t/cake-3-7-adding-multiple-records-one-at-a-time/5788/3 "2019-03-15T07:29:01Z")

</div>

Yeah, that was a mistake wich i corrected immediately after starting this thread.  
Nothing changes, even with the entity passed to FormHelper

Thank you
