x1m
358
6
Laravel

Fill a form by entering primary key

Posted 2 years ago by x1m

Hey guys,

I have a page that contains 2 containers: a form to add freight info and an overview that get's data from DB->all freight info

I want the form to be able to automatically fill it's self with data that belongs to a freight info by entering the first field of the form (primary key).

This is what i use in php, but i want to convert it to laravel(fno is primary key):

<?php
include("connection.php");

if( isset($_POST["fNo"]) && !empty($_POST["fNo"]))
{
    session_start();
    $_SESSION['fNo'] = $_POST['fNo'];
    $fNo = $_POST["fNo"];
    $sql = "SELECT * FROM freightinfo WHERE fNo = $fNo";
    $result = $connect->query($sql);
    if ($result->num_rows > 0) {
        if ($row = $result->fetch_assoc()) {
            $loadedDate = $row["loadedDate"];
            $arrivalDate = $row["arrivalDate"];
            $deliveryDate = $row["deliveryDate"];
            $shippingCompany = $row["shippingCompany"];
            $containerNo = $row["containerNo"];
            $blNo = $row["blNo"];
            $warehouse = $row["warehouse"];
            $freightManager = $row["freightManager"];
            $portLoading = $row["portLoading"];
            $portDischarge = $row["portDischarge"];
            $freightWay = $row["freightWay"];
            $containerType = $row["containerType"];
            $content = $row["content"];
            $weight = $row["weight"];
            $measurement = $row["mesurement"];
            $customsClearence = $row["customsClearence"];
            $notifyParty = $row["notifyParty"];
            $logistics = $row["logistics"];
            $exportGroup = $row["exportGroup"];
            $invoiceDate = $row["invoiceDate"];
            $invoiceNo = $row["invoiceNo"];
            $valueInUsd = $row["valueInUsd"];
            $usdEurRate = $row["usdEurRate"];
            $valueInEur = $row["valueInEur"];
            $importRemarks = $row["importRemarks"];
        }
        else{
            echo "<script type='text/javascript'> alert('FNO not matched with record');</script>";
        }
    }

}
?>
<script>
$(document).ready(function() {
    var events = $('#events');
    var table = $('#example').DataTable({
        dom: 'Bfrtip',
        "scrollX": true,
        "scrollY": "500px",
        "scrollCollapse": true,
        select: true,
        buttons: [
            {
                text: 'Get selected data',
                action: function () {
                    var selectedData = table.row( { selected: true } ).data();
                    //events.prepend( '<div>'+selectedData+'</div>' );
                    $("input[name='fNo']").val(selectedData[0]);
                    $("input[name='loadedDate']").val(selectedData[1]);
                    $("input[name='arrivalDate']").val(selectedData[2]);
                    $("input[name='deliveryDate']").val(selectedData[3]);
                    $("input[name='shippingCompany']").val(selectedData[4]);
                    $("input[name='containerNo']").val(selectedData[5]);
                    $("input[name='blNo']").val(selectedData[6]);
                    $("input[name='warehouse']").val(selectedData[7]);
                    $("input[name='freightManger']").val(selectedData[8]);
                    $("input[name='portLoading']").val(selectedData[9]);
                    $("input[name='portDischarge']").val(selectedData[10]);
                    $("input[name='freightWay']").val(selectedData[11]);
                    $("input[name='containerType']").val(selectedData[12]);
                    $("input[name='content']").val(selectedData[13]);
                    $("input[name='weight']").val(selectedData[14]);
                    $("input[name='measurements']").val(selectedData[15]);
                    $("input[name='customsClearance']").val(selectedData[16]);
                    $("input[name='notifyParty']").val(selectedData[17]);
                    $("input[name='logistics']").val(selectedData[18]);
                    $("input[name='exportCompany']").val(selectedData[19]);
                    $("input[name='invoiceDate']").val(selectedData[20]);
                    $("input[name='invoiceNo']").val(selectedData[21]);
                    $("input[name='valueUsd']").val(selectedData[22]);
                    $("input[name='usdEurRate']").val(selectedData[23]);
                    $("input[name='valueEur']").val(selectedData[24]);
                    $("input[name='importRemarks']").val(selectedData[25]);

                }
            }
        ]
    });


} );
    </script>

Any suggestions?

Please sign in or create an account to participate in this conversation.