sanitize fields of a multidimensional array

  php, session, wordpress

I have a form with fields that are stored in a multidimensional array, I am interested in sanitizing them as is done in this case?

  <form id="propvendor"method="post" action="">




<input type="hidden" id="porc_05" name="porc_05[date]" value="<?php echo $current_date;?>">

<input type="hidden" id="porc_05" name="porc_05[id]" value="<?php echo $id_current;?>">



<textarea placeholder="Comentarios..." id="porc_05" name="porc_05[comment]"></textarea>



<div class="percont">
<input type="hidden" id="pointspossible" value="<?php echo $price;?>"/>


<select name="porc_05[perce]"style="background: #fff;"id="pointsgiven" >
   <option value="0">0%</option>
    <option value="5">5%</option>
    <option value="10">10%</option>
    <option value="15">15%</option>
    <option value="20">20%</option>
    <option value="25">25%</option>
  </select>


<input style="border: none;padding: 0px;color:black;"type="number" id="pointsperc" disabled/>
</div>


<button style="border-radius: 4px;"name="si_prop" type="submit" value=""><i class="fas fa-check"></i></button>


</form>

so i keep them:

if(isset($_POST['si_prop'])){


if(isset($_POST['porc_05'])){

$array = $_POST['porc_05'];
add_post_meta( $prod_id, 'propina5', $array, $unique );  

$data = get_post_meta($prod_id, 'propina5', $single);  
}
}

Result:

echo print_r($data);



Array ( [0] => Array ( [date] => 2021-11-25 22:17:26 [id] => 130 [comment] => retttttttttt ) [1] => Array ( [date] => 2021-11-25 22:17:42 [id] => 130 [comment] => rtrtrtrtr ) [2] => Array ( [date] => 2021-11-25 22:19:04 [id] => 130 [comment] => rtrertewrtewrtt ) [3] => Array ( [date] => 2021-11-25 22:20:12 [id] => 130 [comment] => fghdfgdfg [perce] => 20 ) [4] => Array ( [date] => 2021-11-25 22:20:19 [id] => 130 [comment] => gfgggg [perce] => 100 ) ) 1

How could I correctly add any of these being that I keep everything within the same array?

sanitize_textarea_field()

sanitize_text_field()

Source: Ask PHP

LEAVE A COMMENT