skip to Main Content

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" class="form-control" min="0" placeholder="Quantity" required onclick="getTotal(1)" onkeyup="getTotal(1)">

also how in select?

<select class="form-control select_group product" 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>

3

Answers


  1. <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" />
    
    Login or Signup to reply.
  2. 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" class="form-control" min="0" placeholder="Quantity" required onclick="getTotal(1)" onkeyup="getTotal(1)">
    
    Login or Signup to reply.
  3. try to set attribute to "readonly"

    or if you don’t want to, try programmatically,

    form.onsubmit = function() {
        qty_1.removeAttribute("required")
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search