Home > Software engineering >  Why i can't submit the value of input if it's disabled?
Why i can't submit the value of input if it's disabled?

Time:11-29

My input type has an attributed disabled but whenever i save the value in php it does say " field_name is required" why i can't insert when the input is disabled?

<input disabled type="number" name="qty[]" id="qty_1"  min="0" placeholder="Quantity" required onclick="getTotal(1)" onkeyup="getTotal(1)">

also how in select?

<select  data-row-id="row_<?php echo $x; ?>" id="product_<?php echo $x; ?>" name="product[]" style="width:100%;" onchange="getProductData(<?php echo $x; ?>)" required>
 <option value=""></option>
  <?php foreach ($products as $k => $v): ?>
 <option value="<?php echo $v['id'] ?>"  <?php if($val['product_id'] == $v['id']) { echo "selected='selected'"; } ?>><?php echo $v['name'] ?></option>
  <?php endforeach ?>
</select>

CodePudding user response:

you can't get the value if you submit disabled input. to solve this use readonly instead

<input readonly type="number" name="qty[]" id="qty_1"  min="0" placeholder="Quantity" required onclick="getTotal(1)" onkeyup="getTotal(1)">

CodePudding user response:

<select name="product[]" disabled>
<option value="1">1</option>
<option value="2" selected>2</option>
<option value="3">3</option>
</select>
<input type="hidden" name="product[]" value="2" />
  • Related