-1

I have some form fields. Some form fields data are disabled. The form fields are like live calculation. It calculates fine. Even it insert to database,but the disabled form filed data is not inserting. My Html Code goes here

<form method="POST" oninput="x.value=parseInt(a.value)-parseInt(a.value)*parseInt(b.value)/100;y.value=x.value-parseInt(c.value);x.value=parseInt(x.value);">
<?php
$sql= mysqli_query($con,"SELECT SUM(room_book.price) AS total, room.rn,room.rc,room.tbn,room.rp,room_book.room_number,room_book.bed_book,room_book.rand FROM room INNER JOIN room_book ON room.rn = room_book.room_number WHERE room_book.rand = '$rand'");
while ($row = mysqli_fetch_assoc($sql)) {
        ?>
        <div class="row ">
            <div class="form-group col-md-3">
                <label>Total Price</label>
                 <input value = "<?php echo $row['total']; ?>" id="a" name="price" disabled class="form-control" placeholder="(&#2547;)<?php echo number_format($row['total']); ?>">
            </div>

            <div class="form-group col-md-3">
                <label>Discount In Percentage(%)</label>
                 <input value = "0%" name="prcntg" required id="b" class="form-control" placeholder="0%">
            </div>

        </div>


        <div class="row ">
            <div class="form-group col-md-3">
                <label>Total Payable</label>
                 <input name="x" disabled class="form-control" placeholder="">
            </div>

            <div class="form-group col-md-3">
                <label>Total Paid</label>
                 <input name="paid"  id="c" required class="form-control" placeholder="(&#2547;)<?php echo number_format($row['total']); ?>">
            </div>
        </div>
        <div class="row ">
            <div class="form-group col-md-3">
                <label>Total Due</label>
                 <input name="y" for="c" disabled class="form-control" placeholder="(&#2547;)<?php echo number_format($row['total']); ?>">
            </div>
            <div style="margin-top:24px" class="form-group col-md-3">
                <button name="submit" type="submit" data-loading-text="Loading..." class="btn btn-success"><i class="glyphicon glyphicon-ok-sign"></i> Confirm Invoice</button>
            </div>
        </div>

                    <?php } ?>
        </form>

Those Code runs well. See The screenshot

Form field data


My Php Code

<?php
   if(isset($_POST['submit'])){
       $price  = $_POST['price'];
       $prcntg = $_POST['prcntg'];
       $x      = $_POST['x'] ;
       $paid   = $_POST['paid'];
       $y      = $_POST['y'] ;
       $sql = mysqli_query($con,"UPDATE `room_book` SET prcntg = '$prcntg', x = '$x', paid = '$paid', due = '$y', status = 'Active'");
       if($sql == true){
            echo "<script> window.open('final.php?final=$rand','_self'); </script>";
       }
?>

Database data


Disabled data is remaining 0. How can I solve This.

Mehedi Hasan Siam
  • 1,224
  • 3
  • 12
  • 28
  • Possible duplicate of [values of disabled inputs will not be submitted?](https://stackoverflow.com/questions/1355728/values-of-disabled-inputs-will-not-be-submitted) – CBroe Jul 03 '18 at 06:21
  • There is no duplicates values – Mehedi Hasan Siam Jul 03 '18 at 06:22
  • This _question_ is a duplicate of an old one, meaning that the answers given there apply here as well. Disabled form fields simply are not send with the rest of the form data. – CBroe Jul 03 '18 at 06:24
  • Use hidden input type with the same name – adkstar Jul 03 '18 at 06:25

3 Answers3

1

When you disable any HTML element or use disabled attribute for any HTML element it'll not submit and you cannot see the values. The name itself indicates that the element is disabled. Use Read Only attribute instead.

Hope this helps.

Kishen Nagaraju
  • 2,062
  • 9
  • 17
  • But I need to get that disabled form field data. I need to give the value. But I am getting confused how I give the value. `
    ` I have calculated that disable form field data from this.
    – Mehedi Hasan Siam Jul 03 '18 at 06:33
  • That is why I told you to use readonly attribute. By using this, you can see that you cannot change the value of the HTML element which acts like disabled itself but you'll still get the value in $_POST. – Kishen Nagaraju Jul 03 '18 at 06:34
0

That's because you can't get disabled inputs values. So you should use readonly if you can.

prit.patel
  • 330
  • 3
  • 12
0

disabled means you ignore the data return to controller, so it would be null / not exist. you should use readonly

Arief Setiabudi
  • 101
  • 1
  • 4