(09-15-2023, 03:55 AM)ozornick Wrote: Example.
Before form:
$seriale = set_value("seriale", []);
In input:
echo $seriale[$i] ? $seriale[$i] : "';
P.S. Wrote on phone
There is something wrong , this is my code :
view :
Code:
<?php
$seriale = set_value("seriale", []);
?>
<?php
$attributes = array('class' => 'col-md-12',
'id' => 'myform',
'name' => 'form_macchina',
'method' => 'POST',
'onSubmit' =>'return controllaSerialiDuplicati()'
);
echo form_open (base_url() .'/admin_Macchina/cambia_clienti_massivo',$attributes);
?>
<?php if(!empty($validation) ) :?>
<div class="alert alert-danger border-0 bg-danger fade show py-2">
<div class="d-flex align-items-center">
<div class="font-35 text-white"><i class="bx bxs-message-square-x"></i>
</div>
<div class="ms-3">
<div class="text-white"> <?= $validation->listErrors(); ?></div>
</div>
</div>
</div>
<?php endif ?>
<!-- INIZIO id_clienti -->
<div class='row'>
<div class='col-md-12'>
<label class='col-md-12 col-xs-12 control-label'>Cliente*</label>
<div class='col-md-12 col-xs-12'>
<select id='id_id_clienti' class=' form-control form-control-lg select2' name='id_clienti' required>
<option value=''>Seleziona un valore...</option>
<?php foreach ($tutti_id_clienti as $v) :?>
<option value='<?=$v->id ?>'
<?php if($v->id==set_value('id_clienti')): ?>
selected='selected'
<?php endif ?>
<?php if(isset($_SESSION['id_cliente_selezionato']) AND $v->id==$_SESSION['id_cliente_selezionato']): ?>
selected='selected'
<?php endif ?>
>
<?=$v->nome . ' - ' . $v->stato?>
</option>
<?php endforeach ?>
</select>
</div>
</div>
</div>
<!-- FINE id_clienti -->
<div id="lotto1_50">
<?php for ($i = 1; $i <=50 ; ++$i) : ?>
<div class="row">
<div class="col-md-12">
<label class='col-md-12 col-xs-12 control-label'>Seriale <?=$i ?></label>
<div class='col-md-12 col-xs-12'>
<?php
if(isset( $seriale[$i] )){
$val = $seriale[$i];
}else{
$val ='';
}
?>
<input type='text' value='<?=$val?>' <?php if ($i==1): ?>required='required'<?php endif ?> id='id_class_seriale_<?=$i ?>' class='seriali form-control form-control-lg' name='seriale[]' maxlength='80' >
</div>
</div>
</div>
<?php endfor ?>
controller :
Code:
if($this->request->getMethod() === 'post')
{
$validation = \Config\Services::validation();
$rules=
[
'id_clienti'=>[
'label'=>'Id_clienti',
'rules'=>'required',
'errors'=>[
'required'=>'Cliente obbligatorio',
]
],
'seriale.*'=>[
//'label'=>"Seriale[]",
'rules'=>'seriale_corretto_cambio_clienti|macchina_is_present_Picking|permit_empty',
'errors'=>[
'seriale_corretto_cambio_clienti'=>'Il seriale.* non è un seriale corretto',
'macchina_is_present_Picking'=>'Il seriale.* non è presente in magazzino ',
]
],
];
//dd($rules);
if($this->validate($rules)){
If i insert on field seriale 1 "seriale 1" and on field seriale 2 "seriale 2" ( value that return falsse on seriale_corretto_cambio_clienti) .
When i send the post i have in field seriale 1 the value seriale 2 the other is empty .
edit until line :
found this error : $i start to 1 on field list
change
Code:
<?php
$n = $i-1;
if(isset( $seriale[$n] )){
$val = $seriale[$n];
}else{
$val ='';
}
?>
--------------------------------------------------------------
The error message are two (but the same) :
Il seriale.* non è un seriale corretto
Il seriale.* non è un seriale corretto