Is it possible to store form input directly into variables without using form submission in PHP?

To store form input directly into variables without using form submission in PHP, you can utilize JavaScript to capture the input values and send them to a PHP script using AJAX. This allows you to store the form input in PHP variables without the need for a traditional form submission.

// HTML form with input fields
<form id="myForm">
  <input type="text" id="input1">
  <input type="text" id="input2">
  <button type="button" onclick="submitForm()">Submit</button>
</form>

// JavaScript function to send form data to PHP script
<script>
function submitForm() {
  var input1 = document.getElementById('input1').value;
  var input2 = document.getElementById('input2').value;
  
  var xhr = new XMLHttpRequest();
  xhr.open('POST', 'process.php', true);
  xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  xhr.send('input1=' + input1 + '&input2=' + input2);
}
</script>

// PHP script (process.php) to store form input in variables
<?php
$input1 = $_POST['input1'];
$input2 = $_POST['input2'];

// Now $input1 and $input2 contain the form input values
?>