0

I want to physically print specific data in a PHP form to local printer, this form is part of CRUD PHP project running on localhost.

All solutions that I have seen use window.print(); which leads to a print of the full page, instead of only the data in the form as I need.

My code:

<form method="POST" action="">  
    <div class="form-group">
        <input type="number" name="stu_num" class="form-control" value = "<?php echo $stu_num ; ?>">
    </div>

    <div class="form-group">
        <label >Student Name</label>
        <input type="text" name="stu_name" class="form-control" value = "<?php echo $stu_name ; ?>" >
    </div>

    <div class="form-group">
        <input type="number" name="no_pouch" class="form-control" >
    </div>
    <div class="form-group">

        <input type="number" name="no_contra" class="form-control" >
    </div>

    <div class="form-group">
        <label>Date</label>
        <input type="text" name="date" class="form-control"  value = "<?php echo $date ; ?>">
    </div>        

    <button name="print" class="btn btn-primary">Print</button>
</form>
Skully
  • 2,882
  • 3
  • 20
  • 31
MohamedSalem
  • 37
  • 1
  • 8
  • 3
    `window.print();` is a JS command for the client machine. You want to print the data from the server or the user's machine? This sounds like a JS/HTML question, not PHP – user3783243 Jul 12 '23 at 12:12
  • 1
    this might help: https://stackoverflow.com/questions/2255291/print-the-contents-of-a-div – Rode093 Jul 12 '23 at 12:12
  • @user3783243 this form is part of CRUD php project running in localhost . – MohamedSalem Jul 12 '23 at 12:16
  • Or this might help: https://stackoverflow.com/questions/22313439/printing-data-to-printer-using-php – KIKO Software Jul 12 '23 at 12:21
  • You can also handle it using javascript when the form is submitted and it returns success then prints the data below in a div and call the printer and after print clear the div. https://stackoverflow.com/questions/2255291/print-the-contents-of-a-div – Murad Ali Jul 12 '23 at 12:33
  • Use CSS media queries to define which bits of the page are visible when printing – ADyson Jul 12 '23 at 14:14

0 Answers0