Is it possible to store values in PHP sessions without using a submit button in a form?

Yes, it is possible to store values in PHP sessions without using a submit button in a form by using AJAX to send data to a PHP script that will update the session variables. This can be achieved by making an AJAX request when a certain event occurs, such as clicking a button or entering data into a field.

<?php
session_start();

if(isset($_POST['data'])){
    $_SESSION['value'] = $_POST['data'];
    echo "Value stored in session!";
    exit;
}
?>
<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
    <input type="text" id="data">
    <button id="store">Store Value</button>
    <div id="response"></div>

    <script>
        $(document).ready(function(){
            $("#store").click(function(){
                var data = $("#data").val();
                $.ajax({
                    url: "store_value.php",
                    type: "POST",
                    data: {data: data},
                    success: function(response){
                        $("#response").html(response);
                    }
                });
            });
        });
    </script>
</body>
</html>