$this->StatesxDays->newEntities doesn't have the request data in cakephp 4.4

I have a belongsto association between StatesxDays and three tables (Users (this with two foreign keys: user_id and doctor_id), Groups, Nets), this table has these fields: id, user_id, group_id, net_id, main_gate, doctor_id, date, hour, status, created and modified, when I try to save various records to this table it gives me an error that date, hour and status ar required fields.
This is the code for addUser action:

    public function addUser() {
        $this->loadModel('SourcingEvents');
		$statesxDay = $this->StatesxDays->newEmptyEntity();
        if ($this->request->is('post')) {
			$guardar = false;
			$statesxDay = $this->StatesxDays->newEntities($this->request->getData(), ['associated' => ['Users' => ['onlyIds' => true],
				'Nets' => ['onlyIds' => true], 'Groups' => ['onlyIds' => true], 'Doctor' => ['onlyIds' => true]]]);
			debug($statesxDay);
			foreach($statesxDay as $data){
				$guardar = $this->StatesxDays->save($data);
			}
			if($guardar){
				$this->Flash->success(__('Se modificaron los estados de los usuarios.'));
				return $this->redirect(['action' => 'index']);
			}
            $this->Flash->error(__('No se pudieron modificar los estados de los usuarios'));
		}
		$users = $this->StatesxDays->Users->find('all')->leftJoinWith('Groups')->where(['GroupsUsers.net_id' => $this->controllerUser['net_id']])
			->contain(['Groups.GroupsUsers.Nets', 'Profiles']);
		$eventos = $this->SourcingEvents->find('list');
		$this->set(compact('statesxDay', 'users', 'eventos'));
	}

This is the code for addUser view:

<?php
/**
 * @var \App\View\AppView $this
 * @var iterable<\App\Model\Entity\EstadosxDia> $statesxDays
 */
?>
<div class="statesxDays add_user content">
	<?php
		echo $this->Form->create($statesxDay);
		echo $this->Form->control('estado',['label'=>'Estado','options'=>[1 => 'Alerta verde', 2 => 'Alerta amarillo', 3 => 'Alerta naranja', 4 => 'Alerta rojo'], 'id' => 'estadoId']);
		echo '<div id="selectEVent" style="display:none;">'.$this->Form->control('evento_id',['label'=>'Tipo de evento','options'=>$eventos,'empty'=>'-- Seleccionar evento --']).'</div>';
		echo $this->Form->label('seleccionar', 'Seleccionar todos').$this->Form->checkbox('seleccionar',['id' => 'seleccionar']);
	?>
    <h3><?= __('Cambiar estado de recursos humanos') ?></h3>
    <div class="table-responsive">
        <table>
            <thead>
                <tr>
					<th>Nivel</th>
					<th>Foto</th>
					<th>Email</th>
					<th>Nombre</th>
					<th>Apellido</th>
					<th>Rol</th>
					<th>Celula</th>
					<th>UF</th>
					<th>Nodo</th>
					<th>Estado</th>
					<th>Aislado</th>
				</tr>
			</thead>
			<tbody>
				<?php
					$i = 0;
					foreach ($users as $user):
						$color = '';
						switch ($user->profile_id) {
							case '2':
								$color = '#000000';
								break;
							case '3':
								$color = '#041d54';
								break;
							case '4':
								$color = '#540404';
								break;
							case '5':
								$color = '#6D147A';
								break;
							case '6':
								$color = '#CC7400';
								break;
							case '7':
								$color = '#2E2EBF';
								break;            
							default:
								$color = '#30773D';
								break;
						}
						$group = '';
						$net = '';
						$main_gate = '';
						if($user->profile_id >= 3):
							$group = $user->groups[0]->group_name;
							if($user->profile_id >= 4) $net = $user->groups[0]->groups_users[$i]->net->net_name;
							$main_gate = $user->groups[0]->_joinData->main_gate;
							echo $this->Form->hidden('statesxDays.'.$i.'.group_id',['value'=>$user->groups[0]->id]);
							echo $this->Form->hidden('statesxDays.'.$i.'.net_id',['value'=>$user->groups[0]->_joinData->net_id]);
							if(!empty($main_gate)) echo $this->Form->hidden('statesxDays.'.$i.'.main_gate',['value'=>$main_gate]);
						endif
				?>
				<tr>
					<td><?php echo $user->profile_id; ?></td>
					<td><?php echo $this->Html->image($user->image_file_name_url, ['alt' => $user->image_file_name_filename, 'class' => 'img-circle']); ?></td>
					<td><?php echo $user->email; ?></td>
					<td><?php echo $user->firstname; ?></td> 
					<td><?php echo $user->lastname; ?></td> 
					<td style="background-color:<?php echo $color; ?>;color:#fff"><?php echo $user->profile->name; ?></td> 
					<td><?php echo $group; ?></td> 
					<td><?php echo $net; ?></td> 
					<td><?php if ($user->profile_id > 4) { echo '#'.$main_gate; } else {echo ' - ';} ?></td> 
					<td>
						 <?php echo $this->Form->control('statesxDays.'.$i.'.status',['label'=>false, 'options'=>[1 => 'Alerta verde', 2 => 'Alerta amarillo', 3 => 'Alerta naranja', 4 => 'Alerta rojo'], 'default' => $user->status, 'class'=>'status']); ?>
						 <?php echo $this->Form->hidden('statesxDays.'.$i.'.date',['value'=>date('Y-m-d')]); ?>
						 <?php echo $this->Form->hidden('statesxDays.'.$i.'.hour',['value'=>date('H:i:s')]); ?>
						 <?php echo $this->Form->hidden('statesxDays.'.$i.'.user_id',['value'=>$viewUser['id']]); ?>
						 <?php echo $this->Form->hidden('statesxDays.'.$i.'.doctor_id',['value'=>$user->id]); ?>
					</td>
					<td>
						 <?php echo $this->Form->checkbox('users.'.$i.'.isolated',['value'=>true,'hiddenField' => false, 'class' => 'isolated']); ?>
					</td>
				</tr>
				<?php
						$i++;
					endforeach;
				?>
			</tbody>
		</table>
	</div>
	<?= $this->Form->button(__('Guardar')) ?>
	<?= $this->Form->end() ?>
</div>
<script>
$(function(){
	$('#estadoId').change(function(){
		status = $(this).val();
		$('.status').val(status);
		if(status=="1" || status=="3") $('#selectEVent').show();
		else $('#selectEVent').hide();
	})
})
$(function(){
	$('#seleccionar').change(function() {
		$('.isolated').prop('checked', $(this).is(':checked'));
	});
});
</script>

This is what it shows debug($this->request->getData()):

APP/Controller/StatesxDaysController.php (line 55)
[
  'estado' => '4',
  'evento_id' => '',
  'seleccionar' => '1',
  'statesxDays' => [
    (int) 0 => [
      'group_id' => '1',
      'net_id' => '1',
      'status' => '4',
      'date' => '2023-04-02',
      'hour' => '16:57:22',
      'user_id' => '4',
      'doctor_id' => '4',
    ],
    (int) 1 => [
      'group_id' => '1',
      'net_id' => '1',
      'main_gate' => 'A',
      'status' => '4',
      'date' => '2023-04-02',
      'hour' => '16:57:22',
      'user_id' => '4',
      'doctor_id' => '5',
    ],
    (int) 2 => [
      'group_id' => '1',
      'net_id' => '1',
      'main_gate' => 'B',
      'status' => '4',
      'date' => '2023-04-02',
      'hour' => '16:57:22',
      'user_id' => '4',
      'doctor_id' => '6',
    ],
    (int) 3 => [
      'group_id' => '1',
      'net_id' => '1',
      'main_gate' => 'A',
      'status' => '4',
      'date' => '2023-04-02',
      'hour' => '16:57:22',
      'user_id' => '4',
      'doctor_id' => '7',
    ],
    (int) 4 => [
      'group_id' => '1',
      'net_id' => '1',
      'main_gate' => 'B',
      'status' => '4',
      'date' => '2023-04-02',
      'hour' => '16:57:22',
      'user_id' => '4',
      'doctor_id' => '8',
    ],
    (int) 5 => [
      'group_id' => '1',
      'net_id' => '1',
      'main_gate' => 'A',
      'status' => '4',
      'date' => '2023-04-02',
      'hour' => '16:57:22',
      'user_id' => '4',
      'doctor_id' => '9',
    ],
    (int) 6 => [
      'group_id' => '1',
      'net_id' => '1',
      'main_gate' => 'B',
      'status' => '4',
      'date' => '2023-04-02',
      'hour' => '16:57:22',
      'user_id' => '4',
      'doctor_id' => '10',
    ],
  ],
  'users' => [
    (int) 0 => [
      'isolated' => '1',
    ],
    (int) 1 => [
      'isolated' => '1',
    ],
    (int) 2 => [
      'isolated' => '1',
    ],
    (int) 3 => [
      'isolated' => '1',
    ],
    (int) 4 => [
      'isolated' => '1',
    ],
    (int) 5 => [
      'isolated' => '1',
    ],
    (int) 6 => [
      'isolated' => '1',
    ]
  ],
]

This is what it shows this debug():

APP/Controller/StatesxDaysController.php (line 55)
[
  (int) 0 => object(App\Model\Entity\StatesxDay) id:0 {
    '[new]' => true
    '[accessible]' => [
      'user_id' => true,
      'group_id' => true,
      'net_id' => true,
      'main_gate' => true,
      'pacient_id' => true,
      'doctor_id' => true,
      'date' => true,
      'hour' => true,
      'status' => true,
      'created' => true,
      'modified' => true,
      'user' => true,
      'group' => true,
      'net' => true,
      'pacient' => true,
    ]
    '[dirty]' => [
    ]
    '[original]' => [
    ]
    '[virtual]' => [
    ]
    '[hasErrors]' => true
    '[errors]' => [
      'date' => [
        '_required' => 'This field is required',
      ],
      'hour' => [
        '_required' => 'This field is required',
      ],
      'status' => [
        '_required' => 'This field is required',
      ],
    ]
    '[invalid]' => [
    ]
    '[repository]' => 'StatesxDays'
  },
  (int) 1 => object(App\Model\Entity\StatesxDay) id:1 {
    '[new]' => true
    '[accessible]' => [
      'user_id' => true,
      'group_id' => true,
      'net_id' => true,
      'main_gate' => true,
      'pacient_id' => true,
      'doctor_id' => true,
      'date' => true,
      'hour' => true,
      'status' => true,
      'created' => true,
      'modified' => true,
      'user' => true,
      'group' => true,
      'net' => true,
      'pacient' => true,
    ]
    '[dirty]' => [
    ]
    '[original]' => [
    ]
    '[virtual]' => [
    ]
    '[hasErrors]' => true
    '[errors]' => [
      'date' => [
        '_required' => 'This field is required',
      ],
      'hour' => [
        '_required' => 'This field is required',
      ],
      'status' => [
        '_required' => 'This field is required',
      ],
    ]
    '[invalid]' => [
    ]
    '[repository]' => 'StatesxDays'
  },
]

What am I doing wrong?

Looks to me like the structure of your data doesn’t match what you’re trying to do with it. The data has a key called statesxDays, which is an array of data apparently for that model, but then you call newEntities on that model passing it the top level data, not just the data for statesxDays.

I need to save the association with Users (field user_id), Groups (field group_id), Nets (field net_id) and Doctor (field doctor_id, className Users), what I need is to create an array of form controls, I remember that to do that with cakephp 2.5 I had to add a dot (.) at the end of the control name, but with 4.4 it gives me an exception of empty field, how can I create an array of controls in a form with cakephp 4.4?

Whenever I’m not sure what the control names should look like, I load an entity with all the relevant associations included and debug() it to see the exact structure of the data, then I just match that. It does get more complicated with join data, I’m not sure there’s a universal best way to deal with that.

This is what it shows debug($statesxDay):

APP/Controller/StatesxDaysController.php (line 55)
[
  (int) 0 => object(App\Model\Entity\StatesxDay) id:0 {
    'group_id' => (int) 1
    'net_id' => (int) 1
    'main_gate' => 'B'
    'status' => (int) 1
    'date' => object(Cake\I18n\FrozenDate) id:1 {
      'time' => '2023-04-04 00:00:00.000000-03:00'
      'timezone' => 'America/Argentina/Cordoba'
      'fixedNowTime' => false
    }
    'hour' => '20:09:09'
    'user_id' => (int) 4
    'doctor_id' => (int) 10
    '[new]' => true
    '[accessible]' => [
      'user_id' => true,
      'group_id' => true,
      'net_id' => true,
      'main_gate' => true,
      'pacient_id' => true,
      'doctor_id' => true,
      'date' => true,
      'hour' => true,
      'status' => true,
      'created' => true,
      'modified' => true,
      'user' => true,
      'group' => true,
      'net' => true,
      'pacient' => true,
    ]
    '[dirty]' => [
      'group_id' => true,
      'net_id' => true,
      'main_gate' => true,
      'status' => true,
      'date' => true,
      'hour' => true,
      'user_id' => true,
      'doctor_id' => true,
    ]
    '[original]' => [
    ]
    '[virtual]' => [
    ]
    '[hasErrors]' => false
    '[errors]' => [
    ]
    '[invalid]' => [
    ]
    '[repository]' => 'StatesxDays'
  },
  (int) 1 => object(App\Model\Entity\StatesxDay) id:2 {
    '[new]' => true
    '[accessible]' => [
      'user_id' => true,
      'group_id' => true,
      'net_id' => true,
      'main_gate' => true,
      'pacient_id' => true,
      'doctor_id' => true,
      'date' => true,
      'hour' => true,
      'status' => true,
      'created' => true,
      'modified' => true,
      'user' => true,
      'group' => true,
      'net' => true,
      'pacient' => true,
    ]
    '[dirty]' => [
    ]
    '[original]' => [
    ]
    '[virtual]' => [
    ]
    '[hasErrors]' => true
    '[errors]' => [
      'date' => [
        '_required' => 'This field is required',
      ],
      'hour' => [
        '_required' => 'This field is required',
      ],
      'status' => [
        '_required' => 'This field is required',
      ],
    ]
    '[invalid]' => [
    ]
    '[repository]' => 'StatesxDays'
  },
]

And this is what it shows debug($this->request->getData()):

APP/Controller/StatesxDaysController.php (line 55)
[
  'status' => '4',
  'sourcing_event_id' => '',
  'seleccionar' => '1',
  'statesxDays' => [
    'group_id' => '1',
    'net_id' => '1',
    'main_gate' => 'B',
    'status' => '4',
    'date' => '2023-04-04',
    'hour' => '20:25:07',
    'user_id' => '4',
    'doctor_id' => '10',
  ],
  'users' => [
    'isolated' => '1',
  ],
]

But the statesxDay should be an array of 7 elements, repeting all the fields with different doctor_id

I could create the array of inputs putting brackets at the end of the name of the control and adding ‘multiple’=‘multiple’ in the options array of the control, but is giving me the error The provided value is invalid, this is what it shows debug($statesxDay):

APP/Controller/StatesxDaysController.php (line 55)
[
  (int) 0 => object(App\Model\Entity\StatesxDay) id:0 {
    '[new]' => true
    '[accessible]' => [
      'user_id' => true,
      'group_id' => true,
      'net_id' => true,
      'main_gate' => true,
      'pacient_id' => true,
      'doctor_id' => true,
      'date' => true,
      'hour' => true,
      'status' => true,
      'created' => true,
      'modified' => true,
      'user' => true,
      'group' => true,
      'net' => true,
      'pacient' => true,
    ]
    '[dirty]' => [
    ]
    '[original]' => [
    ]
    '[virtual]' => [
    ]
    '[hasErrors]' => true
    '[errors]' => [
      'date' => [
        '_required' => 'This field is required',
      ],
      'hour' => [
        '_required' => 'This field is required',
      ],
      'status' => [
        '_required' => 'This field is required',
      ],
    ]
    '[invalid]' => [
    ]
    '[repository]' => 'StatesxDays'
  },
  (int) 1 => object(App\Model\Entity\StatesxDay) id:1 {
    '[new]' => true
    '[accessible]' => [
      'user_id' => true,
      'group_id' => true,
      'net_id' => true,
      'main_gate' => true,
      'pacient_id' => true,
      'doctor_id' => true,
      'date' => true,
      'hour' => true,
      'status' => true,
      'created' => true,
      'modified' => true,
      'user' => true,
      'group' => true,
      'net' => true,
      'pacient' => true,
    ]
    '[dirty]' => [
    ]
    '[original]' => [
    ]
    '[virtual]' => [
    ]
    '[hasErrors]' => true
    '[errors]' => [
      'date' => [
        '_required' => 'This field is required',
      ],
      'hour' => [
        '_required' => 'This field is required',
      ],
      'status' => [
        '_required' => 'This field is required',
      ],
    ]
    '[invalid]' => [
    ]
    '[repository]' => 'StatesxDays'
  },
  (int) 2 => object(App\Model\Entity\StatesxDay) id:2 {
    '[new]' => true
    '[accessible]' => [
      'user_id' => true,
      'group_id' => true,
      'net_id' => true,
      'main_gate' => true,
      'pacient_id' => true,
      'doctor_id' => true,
      'date' => true,
      'hour' => true,
      'status' => true,
      'created' => true,
      'modified' => true,
      'user' => true,
      'group' => true,
      'net' => true,
      'pacient' => true,
    ]
    '[dirty]' => [
    ]
    '[original]' => [
    ]
    '[virtual]' => [
    ]
    '[hasErrors]' => true
    '[errors]' => [
      'date' => [
        '_required' => 'This field is required',
      ],
      'hour' => [
        '_required' => 'This field is required',
      ],
      'status' => [
        '_required' => 'This field is required',
      ],
    ]
    '[invalid]' => [
    ]
    '[repository]' => 'StatesxDays'
  },
  (int) 3 => object(App\Model\Entity\StatesxDay) id:3 {
    '[new]' => true
    '[accessible]' => [
      'user_id' => true,
      'group_id' => true,
      'net_id' => true,
      'main_gate' => true,
      'pacient_id' => true,
      'doctor_id' => true,
      'date' => true,
      'hour' => true,
      'status' => true,
      'created' => true,
      'modified' => true,
      'user' => true,
      'group' => true,
      'net' => true,
      'pacient' => true,
    ]
    '[dirty]' => [
    ]
    '[original]' => [
    ]
    '[virtual]' => [
    ]
    '[hasErrors]' => true
    '[errors]' => [
      'date' => [
        '_required' => 'This field is required',
      ],
      'hour' => [
        '_required' => 'This field is required',
      ],
      'status' => [
        '_required' => 'This field is required',
      ],
    ]
    '[invalid]' => [
    ]
    '[repository]' => 'StatesxDays'
  },
  (int) 4 => object(App\Model\Entity\StatesxDay) id:4 {
    '[new]' => true
    '[accessible]' => [
      'user_id' => true,
      'group_id' => true,
      'net_id' => true,
      'main_gate' => true,
      'pacient_id' => true,
      'doctor_id' => true,
      'date' => true,
      'hour' => true,
      'status' => true,
      'created' => true,
      'modified' => true,
      'user' => true,
      'group' => true,
      'net' => true,
      'pacient' => true,
    ]
    '[dirty]' => [
    ]
    '[original]' => [
    ]
    '[virtual]' => [
    ]
    '[hasErrors]' => true
    '[errors]' => [
      'date' => [
        '_required' => 'This field is required',
      ],
      'hour' => [
        '_required' => 'This field is required',
      ],
      'status' => [
        '_required' => 'This field is required',
      ],
    ]
    '[invalid]' => [
    ]
    '[repository]' => 'StatesxDays'
  },
  (int) 5 => object(App\Model\Entity\StatesxDay) id:5 {
    '[new]' => true
    '[accessible]' => [
      'user_id' => true,
      'group_id' => true,
      'net_id' => true,
      'main_gate' => true,
      'pacient_id' => true,
      'doctor_id' => true,
      'date' => true,
      'hour' => true,
      'status' => true,
      'created' => true,
      'modified' => true,
      'user' => true,
      'group' => true,
      'net' => true,
      'pacient' => true,
    ]
    '[dirty]' => [
    ]
    '[original]' => [
    ]
    '[virtual]' => [
    ]
    '[hasErrors]' => true
    '[errors]' => [
      'date' => [
        '_required' => 'This field is required',
      ],
      'hour' => [
        '_required' => 'This field is required',
      ],
      'status' => [
        '_required' => 'This field is required',
      ],
    ]
    '[invalid]' => [
    ]
    '[repository]' => 'StatesxDays'
  },
  (int) 6 => object(App\Model\Entity\StatesxDay) id:6 {
    '[new]' => true
    '[accessible]' => [
      'user_id' => true,
      'group_id' => true,
      'net_id' => true,
      'main_gate' => true,
      'pacient_id' => true,
      'doctor_id' => true,
      'date' => true,
      'hour' => true,
      'status' => true,
      'created' => true,
      'modified' => true,
      'user' => true,
      'group' => true,
      'net' => true,
      'pacient' => true,
    ]
    '[dirty]' => [
    ]
    '[original]' => [
    ]
    '[virtual]' => [
    ]
    '[hasErrors]' => true
    '[errors]' => [
      'date' => [
        '_required' => 'This field is required',
      ],
      'hour' => [
        '_required' => 'This field is required',
      ],
      'status' => [
        '_required' => 'This field is required',
      ],
    ]
    '[invalid]' => [
    ]
    '[repository]' => 'StatesxDays'
  },
  (int) 7 => object(App\Model\Entity\StatesxDay) id:7 {
    '[new]' => true
    '[accessible]' => [
      'user_id' => true,
      'group_id' => true,
      'net_id' => true,
      'main_gate' => true,
      'pacient_id' => true,
      'doctor_id' => true,
      'date' => true,
      'hour' => true,
      'status' => true,
      'created' => true,
      'modified' => true,
      'user' => true,
      'group' => true,
      'net' => true,
      'pacient' => true,
    ]
    '[dirty]' => [
    ]
    '[original]' => [
    ]
    '[virtual]' => [
    ]
    '[hasErrors]' => true
    '[errors]' => [
      'date' => [
        '_required' => 'This field is required',
      ],
      'hour' => [
        '_required' => 'This field is required',
      ],
      'status' => [
        '_required' => 'This field is required',
      ],
    ]
    '[invalid]' => [
    ]
    '[repository]' => 'StatesxDays'
  },
  (int) 8 => object(App\Model\Entity\StatesxDay) id:8 {
    '[new]' => true
    '[accessible]' => [
      'user_id' => true,
      'group_id' => true,
      'net_id' => true,
      'main_gate' => true,
      'pacient_id' => true,
      'doctor_id' => true,
      'date' => true,
      'hour' => true,
      'status' => true,
      'created' => true,
      'modified' => true,
      'user' => true,
      'group' => true,
      'net' => true,
      'pacient' => true,
    ]
    '[dirty]' => [
    ]
    '[original]' => [
    ]
    '[virtual]' => [
    ]
    '[hasErrors]' => true
    '[errors]' => [
      'date' => [
        '_required' => 'This field is required',
      ],
      'hour' => [
        '_required' => 'This field is required',
      ],
      'status' => [
        '_required' => 'This field is required',
      ],
    ]
    '[invalid]' => [
    ]
    '[repository]' => 'StatesxDays'
  },
]

How can I solve this issue?

I think the problem is in the hidden controls, because is giving me the error The provided value is invalid, how can I create a hidden control for a date, time and integer value? Because the hidden control is of type string.

What line, specifically, is giving you the “provided value is invalid” error?

It shows me the invalid array in the debug($statesxDay), this is what it shows:

APP/Controller/StatesxDaysController.php (line 54)
[
  (int) 0 => object(App\Model\Entity\StatesxDay) id:0 {
    '[new]' => true
    '[accessible]' => [
      'user_id' => true,
      'group_id' => true,
      'net_id' => true,
      'main_gate' => true,
      'pacient_id' => true,
      'doctor_id' => true,
      'date' => true,
      'hour' => true,
      'status' => true,
      'created' => true,
      'modified' => true,
      'user' => true,
      'group' => true,
      'net' => true,
      'pacient' => true,
    ]
    '[dirty]' => [
    ]
    '[original]' => [
    ]
    '[virtual]' => [
    ]
    '[hasErrors]' => true
    '[errors]' => [
      'user_id' => [
        'integer' => 'The provided value is invalid',
      ],
      'group_id' => [
        'integer' => 'The provided value is invalid',
      ],
      'net_id' => [
        'integer' => 'The provided value is invalid',
      ],
      'main_gate' => [
        'scalar' => 'The provided value is invalid',
        'maxLength' => 'The provided value is invalid',
      ],
      'doctor_id' => [
        'integer' => 'The provided value is invalid',
      ],
      'date' => [
        'date' => 'The provided value is invalid',
      ],
      'hour' => [
        'time' => 'The provided value is invalid',
      ],
      'status' => [
        'integer' => 'The provided value is invalid',
      ],
    ]
    '[invalid]' => [
      'group_id' => [
        (int) 0 => '1',
        (int) 1 => '1',
        (int) 2 => '1',
        (int) 3 => '1',
        (int) 4 => '1',
        (int) 5 => '1',
        (int) 6 => '1',
      ],
      'net_id' => [
        (int) 0 => '1',
        (int) 1 => '1',
        (int) 2 => '1',
        (int) 3 => '1',
        (int) 4 => '1',
        (int) 5 => '1',
        (int) 6 => '1',
      ],
      'main_gate' => [
        (int) 0 => '',
        (int) 1 => 'A',
        (int) 2 => 'B',
        (int) 3 => 'A',
        (int) 4 => 'B',
        (int) 5 => 'A',
        (int) 6 => 'B',
      ],
      'status' => [
        (int) 0 => '4',
        (int) 1 => '4',
        (int) 2 => '4',
        (int) 3 => '4',
        (int) 4 => '4',
        (int) 5 => '4',
        (int) 6 => '4',
      ],
      'date' => [
        (int) 0 => '2023-04-06',
        (int) 1 => '2023-04-06',
        (int) 2 => '2023-04-06',
        (int) 3 => '2023-04-06',
        (int) 4 => '2023-04-06',
        (int) 5 => '2023-04-06',
        (int) 6 => '2023-04-06',
      ],
      'hour' => [
        (int) 0 => '20:44:59',
        (int) 1 => '20:44:59',
        (int) 2 => '20:44:59',
        (int) 3 => '20:44:59',
        (int) 4 => '20:44:59',
        (int) 5 => '20:44:59',
        (int) 6 => '20:44:59',
      ],
      'user_id' => [
        (int) 0 => '4',
        (int) 1 => '4',
        (int) 2 => '4',
        (int) 3 => '4',
        (int) 4 => '4',
        (int) 5 => '4',
        (int) 6 => '4',
      ],
      'doctor_id' => [
        (int) 0 => '4',
        (int) 1 => '5',
        (int) 2 => '6',
        (int) 3 => '7',
        (int) 4 => '8',
        (int) 5 => '9',
        (int) 6 => '10',
      ],
    ]
    '[repository]' => 'StatesxDays'
  },
  (int) 1 => object(App\Model\Entity\StatesxDay) id:1 {
    '[new]' => true
    '[accessible]' => [
      'user_id' => true,
      'group_id' => true,
      'net_id' => true,
      'main_gate' => true,
      'pacient_id' => true,
      'doctor_id' => true,
      'date' => true,
      'hour' => true,
      'status' => true,
      'created' => true,
      'modified' => true,
      'user' => true,
      'group' => true,
      'net' => true,
      'pacient' => true,
    ]
    '[dirty]' => [
    ]
    '[original]' => [
    ]
    '[virtual]' => [
    ]
    '[hasErrors]' => true
    '[errors]' => [
      'date' => [
        '_required' => 'This field is required',
      ],
      'hour' => [
        '_required' => 'This field is required',
      ],
      'status' => [
        '_required' => 'This field is required',
      ],
    ]
    '[invalid]' => [
    ]
    '[repository]' => 'StatesxDays'
  },
]

And also I need to ignore the validation for some controls that are in the form but don’t belong to the entity, these are the three controls created at the top of the form (estado, sourcing_event_id and seleccionar)

From the data you’ve shown, group_id is an array, not an integer. Does that help you figure out what’s wrong in the way you’re setting up your form?

Yes, I understand that, but I need it to be an array because I am saving various entities into the table, how do I have to create the controls in the form so that it can add various records in the StatesxDays table or is there another method besides newEntities that can get all the request data as an array?

I changed the way I create the controls in the form, this is what it shows debug($this->request->getData()):

APP/Controller/StatesxDaysController.php (line 55)
[
  'estado' => '4',
  'sourcing_event_id' => '',
  'seleccionar' => '1',
  'statesxDays' => [
    (int) 0 => [
      'group_id' => '1',
      'net_id' => '1',
      'main_gate' => '',
      'status' => '4',
      'date' => '2023-04-07',
      'hour' => '16:17:49',
      'user_id' => '4',
      'doctor_id' => '4',
    ],
    (int) 1 => [
      'group_id' => '1',
      'net_id' => '1',
      'main_gate' => 'A',
      'status' => '4',
      'date' => '2023-04-07',
      'hour' => '16:17:49',
      'user_id' => '4',
      'doctor_id' => '5',
    ],
    (int) 2 => [
      'group_id' => '1',
      'net_id' => '1',
      'main_gate' => 'B',
      'status' => '4',
      'date' => '2023-04-07',
      'hour' => '16:17:49',
      'user_id' => '4',
      'doctor_id' => '6',
    ],
    (int) 3 => [
      'group_id' => '1',
      'net_id' => '1',
      'main_gate' => 'A',
      'status' => '4',
      'date' => '2023-04-07',
      'hour' => '16:17:49',
      'user_id' => '4',
      'doctor_id' => '7',
    ],
    (int) 4 => [
      'group_id' => '1',
      'net_id' => '1',
      'main_gate' => 'B',
      'status' => '4',
      'date' => '2023-04-07',
      'hour' => '16:17:49',
      'user_id' => '4',
      'doctor_id' => '8',
    ],
    (int) 5 => [
      'group_id' => '1',
      'net_id' => '1',
      'main_gate' => 'A',
      'status' => '4',
      'date' => '2023-04-07',
      'hour' => '16:17:49',
      'user_id' => '4',
      'doctor_id' => '9',
    ],
    (int) 6 => [
      'group_id' => '1',
      'net_id' => '1',
      'main_gate' => 'B',
      'status' => '4',
      'date' => '2023-04-07',
      'hour' => '16:17:49',
      'user_id' => '4',
      'doctor_id' => '10',
    ],
  ],
  'users' => [
    (int) 0 => [
      'isolated' => '1',
    ],
    (int) 1 => [
      'isolated' => '1',
    ],
    (int) 2 => [
      'isolated' => '1',
    ],
    (int) 3 => [
      'isolated' => '1',
    ],
    (int) 4 => [
      'isolated' => '1',
    ],
    (int) 5 => [
      'isolated' => '1',
    ],
    (int) 6 => [
      'isolated' => '1',
    ],
  ],
]

And this is what it shows debug($statesxDay):

APP/Controller/StatesxDaysController.php (line 55)
[
  (int) 0 => object(App\Model\Entity\StatesxDay) id:0 {
    '[new]' => true
    '[accessible]' => [
      'user_id' => true,
      'group_id' => true,
      'net_id' => true,
      'main_gate' => true,
      'pacient_id' => true,
      'doctor_id' => true,
      'date' => true,
      'hour' => true,
      'status' => true,
      'created' => true,
      'modified' => true,
      'user' => true,
      'group' => true,
      'net' => true,
      'pacient' => true,
    ]
    '[dirty]' => [
    ]
    '[original]' => [
    ]
    '[virtual]' => [
    ]
    '[hasErrors]' => true
    '[errors]' => [
      'date' => [
        '_required' => 'This field is required',
      ],
      'hour' => [
        '_required' => 'This field is required',
      ],
      'status' => [
        '_required' => 'This field is required',
      ],
    ]
    '[invalid]' => [
    ]
    '[repository]' => 'StatesxDays'
  },
  (int) 1 => object(App\Model\Entity\StatesxDay) id:1 {
    '[new]' => true
    '[accessible]' => [
      'user_id' => true,
      'group_id' => true,
      'net_id' => true,
      'main_gate' => true,
      'pacient_id' => true,
      'doctor_id' => true,
      'date' => true,
      'hour' => true,
      'status' => true,
      'created' => true,
      'modified' => true,
      'user' => true,
      'group' => true,
      'net' => true,
      'pacient' => true,
    ]
    '[dirty]' => [
    ]
    '[original]' => [
    ]
    '[virtual]' => [
    ]
    '[hasErrors]' => true
    '[errors]' => [
      'date' => [
        '_required' => 'This field is required',
      ],
      'hour' => [
        '_required' => 'This field is required',
      ],
      'status' => [
        '_required' => 'This field is required',
      ],
    ]
    '[invalid]' => [
    ]
    '[repository]' => 'StatesxDays'
  },
]

This data structure looks closer. Can you share your current line(s) of code that creates the $statesxDay variable?

This is the code for add_user view:

<?php
/**
 * @var \App\View\AppView $this
 * @var iterable<\App\Model\Entity\statesxDays> $statesxDays
 */
?>
<div class="statesxDays add_user content">
	<?php
		echo $this->Form->create($statesxDay);
		echo $this->Form->control('estado',['label'=>'Estado','options'=>[1 => 'Alerta verde', 2 => 'Alerta amarillo', 3 => 'Alerta naranja', 4 => 'Alerta rojo'], 'id' => 'estadoId']);
		echo '<div id="selectEVent" style="display:none;">'.$this->Form->control('sourcing_event_id',['label'=>'Tipo de evento','options'=>$sourcingEvents,'empty'=>'-- Seleccionar evento --']).'</div>';
		echo $this->Form->label('seleccionar', 'Seleccionar todos').$this->Form->checkbox('seleccionar',['id' => 'seleccionar']);
	?>
    <h3><?= __('Cambiar estado de recursos humanos') ?></h3>
    <div class="table-responsive">
        <table>
            <thead>
                <tr>
					<th>Nivel</th>
					<th>Foto</th>
					<th>Email</th>
					<th>Nombre</th>
					<th>Apellido</th>
					<th>Rol</th>
					<th>Celula</th>
					<th>UF</th>
					<th>Nodo</th>
					<th>Estado</th>
					<th>Aislado</th>
				</tr>
			</thead>
			<tbody>
				<?php
					$j = 0;
					foreach ($users as $user):
						$color = '';
						switch ($user->profile_id) {
							case '2':
								$color = '#000000';
								break;
							case '3':
								$color = '#041d54';
								break;
							case '4':
								$color = '#540404';
								break;
							case '5':
								$color = '#6D147A';
								break;
							case '6':
								$color = '#CC7400';
								break;
							case '7':
								$color = '#2E2EBF';
								break;            
							default:
								$color = '#30773D';
								break;
						}
				?>
				<tr>
					<td>
						<?php
							echo $user->profile_id;
							$group = '';
							$net = '';
							$main_gate = '';
							if($user->profile_id >= 3):
								$group = $user->groups[0]->group_name;
								if(!empty($user->groups[0]->_joinData->net_id)){
									$i = $user->groups[0]->_joinData->net_id - 1;
									$net = $this->Html->link($user->groups[0]->nets[$i]->net_name, ['controller' => 'Nets', 'action' => 'view', $user->groups[0]->_joinData->net_id]);
								}
								$main_gate = $user->groups[0]->_joinData->main_gate;
								echo $this->Form->hidden('statesxDays.'.$j.'.group_id',['value'=>$user->groups[0]->id]);
								echo $this->Form->hidden('statesxDays.'.$j.'.net_id',['value'=>$user->groups[0]->_joinData->net_id]);
								echo $this->Form->hidden('statesxDays.'.$j.'.main_gate',['value'=>$main_gate]);
							endif
						?>
					</td>
					<td><?= $this->Html->image($user->image_file_name_url, ['title' => $user->image_file_name_filename, 'class' => 'img-circle']) ?></td>
					<td><?= $user->email ?></td>
					<td><?= $user->firstname ?></td> 
					<td><?= $user->lastname ?></td> 
					<td style="background-color:<?= $color ?>;color:#fff"><?= $user->profile->name ?></td> 
					<td><?= $group ?></td> 
					<td><?= $net ?></td> 
					<td><?= (!empty($main_gate)) ? '#'.$main_gate : ' - ' ?></td> 
					<td>
						<?= $this->Form->control('statesxDays.'.$j.'.status',['label'=>false, 'options'=>[1 => 'Alerta verde', 2 => 'Alerta amarillo', 3 => 'Alerta naranja', 4 => 'Alerta rojo'], 'class'=>'status']) ?>
						<?= $this->Html->tag('div',
							$this->Form->date('statesxDays.'.$j.'.date',['value'=>date('Y-m-d')]) .
							$this->Form->time('statesxDays.'.$j.'.hour',['value'=>date('H:i:s')]),
							['class' => 'input_oculto']) ?>
						<?= $this->Form->hidden('statesxDays.'.$j.'.user_id',['value'=>$viewUser['id']]) ?>
						<?= $this->Form->hidden('statesxDays.'.$j.'.doctor_id',['value'=>$user->id]) ?>
					</td>
					<td>
						 <?= $this->Form->checkbox('users.'.$j.'.isolated',['value'=>true,'hiddenField' => false, 'class' => 'isolated']) ?>
					</td>
				</tr>
				<?php
						$j++;
					endforeach;
				?>
			</tbody>
		</table>
	</div>
	<?= $this->Form->button(__('Guardar')) ?>
	<?= $this->Form->end() ?>
</div>
<script>
$(function(){
	$('#estadoId').change(function(){
		status = $(this).val();
		$('.status').val(status);
		if(status=="1" || status=="3") $('#selectEVent').show();
		else $('#selectEVent').hide();
	})
})
$(function(){
	$('#seleccionar').change(function() {
		$('.isolated').prop('checked', $(this).is(':checked'));
	});
});
$(function(){
    $(document).ready(function() {  
		$('.input_oculto').hide();
	});
});
</script>

And this is the code for addUser action:

    public function addUser() {
        $this->loadModel('SourcingEvents');
		$statesxDay = $this->StatesxDays->newEmptyEntity();
        if ($this->request->is('post')) {
			$guardar = false;
			$statesxDay = $this->StatesxDays->newEntities($this->request->getData());
			foreach($statesxDay as $data){
				$guardar = $this->StatesxDays->save($data);
			}
			if($guardar){
				$this->Flash->success(__('Se modificaron los estados de los usuarios.'));
				return $this->redirect(['action' => 'index']);
			}
            $this->Flash->error(__('No se pudieron modificar los estados de los usuarios'));
		}
		$users = $this->StatesxDays->Users->find('all')->leftJoinWith('Groups')->where(['GroupsUsers.net_id' => $this->controllerUser['net_id']])
			->contain(['Groups' => ['Nets'], 'Profiles']);
		$sourcingEvents = $this->SourcingEvents->find('list');
		$this->set(compact('statesxDay', 'users', 'sourcingEvents'));
	}

If you are doing

$statesxDay = $this->StatesxDays->newEntities($this->request->getData());

why do you also have a statesxDays key in your data? I think you would want to pass $this->request->getData('statesxDays').

Thank you Zuluru, now is working fine, but I also need to pass the Users entity to $this->request->getData, because I am trying to modify one field from this table, how can I pass statesxDays and users entities to request data?

So maybe what you really really want is not to make a bunch of statesxDay entities, but to patch a user entity that will get a bunch of statesxDay entities? Along the lines of

$user = $this->StatesxDays->Users->patchEntity($this->request->getData());

with a few related changes elsewhere.

That’s exactly what I want to do, when I do what you say it only puts the users entity’s fields, not the statesxdays, but it saves the records in statesxDays table but the fields with null values, the only field that isn’t null is status.
This is what it shows debug($doctors) after the $doctors = $this->StatesxDays->Doctor->newEntities($this->request->getData(‘statesxDays’)):

APP/Controller/StatesxDaysController.php (line 54)
[
  (int) 0 => object(App\Model\Entity\User) id:0 {
    'status' => (int) 4
    '[new]' => true
    '[accessible]' => [
      'username' => true,
      'password' => true,
      'email' => true,
      'firstname' => true,
      'lastname' => true,
      'created' => true,
      'modified' => true,
      'profile_id' => true,
      'referrer_id' => true,
      'active' => true,
      'image_file_name_url' => true,
      'image_file_name' => true,
      'image_file_name_filename' => true,
      'map_lat' => true,
      'map_long' => true,
      'code' => true,
      'status' => true,
      'isolated' => true,
      'token' => true,
      'aro' => true,
      'profile' => true,
      'referrer' => true,
      'statesx_days' => true,
      'doctors' => true,
      'events_users' => true,
      'observations' => true,
      'pacients' => true,
      'status_groups' => true,
      'stocks_users' => true,
      'turns' => true,
      'doctor' => true,
      'groups' => true,
    ]
    '[dirty]' => [
      'status' => true,
    ]
    '[original]' => [
    ]
    '[virtual]' => [
    ]
    '[hasErrors]' => false
    '[errors]' => [
    ]
    '[invalid]' => [
    ]
    '[repository]' => 'Doctor'
  },
  (int) 1 => object(App\Model\Entity\User) id:1 {
    'status' => (int) 4
    '[new]' => true
    '[accessible]' => [
      'username' => true,
      'password' => true,
      'email' => true,
      'firstname' => true,
      'lastname' => true,
      'created' => true,
      'modified' => true,
      'profile_id' => true,
      'referrer_id' => true,
      'active' => true,
      'image_file_name_url' => true,
      'image_file_name' => true,
      'image_file_name_filename' => true,
      'map_lat' => true,
      'map_long' => true,
      'code' => true,
      'status' => true,
      'isolated' => true,
      'token' => true,
      'aro' => true,
      'profile' => true,
      'referrer' => true,
      'statesx_days' => true,
      'doctors' => true,
      'events_users' => true,
      'observations' => true,
      'pacients' => true,
      'status_groups' => true,
      'stocks_users' => true,
      'turns' => true,
      'doctor' => true,
      'groups' => true,
    ]
    '[dirty]' => [
      'status' => true,
    ]
    '[original]' => [
    ]
    '[virtual]' => [
    ]
    '[hasErrors]' => false
    '[errors]' => [
    ]
    '[invalid]' => [
    ]
    '[repository]' => 'Doctor'
  },
  (int) 2 => object(App\Model\Entity\User) id:2 {
    'status' => (int) 4
    '[new]' => true
    '[accessible]' => [
      'username' => true,
      'password' => true,
      'email' => true,
      'firstname' => true,
      'lastname' => true,
      'created' => true,
      'modified' => true,
      'profile_id' => true,
      'referrer_id' => true,
      'active' => true,
      'image_file_name_url' => true,
      'image_file_name' => true,
      'image_file_name_filename' => true,
      'map_lat' => true,
      'map_long' => true,
      'code' => true,
      'status' => true,
      'isolated' => true,
      'token' => true,
      'aro' => true,
      'profile' => true,
      'referrer' => true,
      'statesx_days' => true,
      'doctors' => true,
      'events_users' => true,
      'observations' => true,
      'pacients' => true,
      'status_groups' => true,
      'stocks_users' => true,
      'turns' => true,
      'doctor' => true,
      'groups' => true,
    ]
    '[dirty]' => [
      'status' => true,
    ]
    '[original]' => [
    ]
    '[virtual]' => [
    ]
    '[hasErrors]' => false
    '[errors]' => [
    ]
    '[invalid]' => [
    ]
    '[repository]' => 'Doctor'
  },
  (int) 3 => object(App\Model\Entity\User) id:3 {
    'status' => (int) 4
    '[new]' => true
    '[accessible]' => [
      'username' => true,
      'password' => true,
      'email' => true,
      'firstname' => true,
      'lastname' => true,
      'created' => true,
      'modified' => true,
      'profile_id' => true,
      'referrer_id' => true,
      'active' => true,
      'image_file_name_url' => true,
      'image_file_name' => true,
      'image_file_name_filename' => true,
      'map_lat' => true,
      'map_long' => true,
      'code' => true,
      'status' => true,
      'isolated' => true,
      'token' => true,
      'aro' => true,
      'profile' => true,
      'referrer' => true,
      'statesx_days' => true,
      'doctors' => true,
      'events_users' => true,
      'observations' => true,
      'pacients' => true,
      'status_groups' => true,
      'stocks_users' => true,
      'turns' => true,
      'doctor' => true,
      'groups' => true,
    ]
    '[dirty]' => [
      'status' => true,
    ]
    '[original]' => [
    ]
    '[virtual]' => [
    ]
    '[hasErrors]' => false
    '[errors]' => [
    ]
    '[invalid]' => [
    ]
    '[repository]' => 'Doctor'
  },
  (int) 4 => object(App\Model\Entity\User) id:4 {
    'status' => (int) 4
    '[new]' => true
    '[accessible]' => [
      'username' => true,
      'password' => true,
      'email' => true,
      'firstname' => true,
      'lastname' => true,
      'created' => true,
      'modified' => true,
      'profile_id' => true,
      'referrer_id' => true,
      'active' => true,
      'image_file_name_url' => true,
      'image_file_name' => true,
      'image_file_name_filename' => true,
      'map_lat' => true,
      'map_long' => true,
      'code' => true,
      'status' => true,
      'isolated' => true,
      'token' => true,
      'aro' => true,
      'profile' => true,
      'referrer' => true,
      'statesx_days' => true,
      'doctors' => true,
      'events_users' => true,
      'observations' => true,
      'pacients' => true,
      'status_groups' => true,
      'stocks_users' => true,
      'turns' => true,
      'doctor' => true,
      'groups' => true,
    ]
    '[dirty]' => [
      'status' => true,
    ]
    '[original]' => [
    ]
    '[virtual]' => [
    ]
    '[hasErrors]' => false
    '[errors]' => [
    ]
    '[invalid]' => [
    ]
    '[repository]' => 'Doctor'
  },
  (int) 5 => object(App\Model\Entity\User) id:5 {
    'status' => (int) 4
    '[new]' => true
    '[accessible]' => [
      'username' => true,
      'password' => true,
      'email' => true,
      'firstname' => true,
      'lastname' => true,
      'created' => true,
      'modified' => true,
      'profile_id' => true,
      'referrer_id' => true,
      'active' => true,
      'image_file_name_url' => true,
      'image_file_name' => true,
      'image_file_name_filename' => true,
      'map_lat' => true,
      'map_long' => true,
      'code' => true,
      'status' => true,
      'isolated' => true,
      'token' => true,
      'aro' => true,
      'profile' => true,
      'referrer' => true,
      'statesx_days' => true,
      'doctors' => true,
      'events_users' => true,
      'observations' => true,
      'pacients' => true,
      'status_groups' => true,
      'stocks_users' => true,
      'turns' => true,
      'doctor' => true,
      'groups' => true,
    ]
    '[dirty]' => [
      'status' => true,
    ]
    '[original]' => [
    ]
    '[virtual]' => [
    ]
    '[hasErrors]' => false
    '[errors]' => [
    ]
    '[invalid]' => [
    ]
    '[repository]' => 'Doctor'
  },
  (int) 6 => object(App\Model\Entity\User) id:6 {
    'status' => (int) 4
    '[new]' => true
    '[accessible]' => [
      'username' => true,
      'password' => true,
      'email' => true,
      'firstname' => true,
      'lastname' => true,
      'created' => true,
      'modified' => true,
      'profile_id' => true,
      'referrer_id' => true,
      'active' => true,
      'image_file_name_url' => true,
      'image_file_name' => true,
      'image_file_name_filename' => true,
      'map_lat' => true,
      'map_long' => true,
      'code' => true,
      'status' => true,
      'isolated' => true,
      'token' => true,
      'aro' => true,
      'profile' => true,
      'referrer' => true,
      'statesx_days' => true,
      'doctors' => true,
      'events_users' => true,
      'observations' => true,
      'pacients' => true,
      'status_groups' => true,
      'stocks_users' => true,
      'turns' => true,
      'doctor' => true,
      'groups' => true,
    ]
    '[dirty]' => [
      'status' => true,
    ]
    '[original]' => [
    ]
    '[virtual]' => [
    ]
    '[hasErrors]' => false
    '[errors]' => [
    ]
    '[invalid]' => [
    ]
    '[repository]' => 'Doctor'
  },
]

How can I solve this issue?

Not
$doctors = $this->StatesxDays->Doctor->newEntities($this->request->getData(‘statesxDays’)):
but
$doctor = $this->StatesxDays->Doctor->newEntity($this->request->getData()):

And you might need to change your input field name from statesxDays to statesx_days.