Hi,

In this blog we are going to know about Data submission without submit button in PHP page by using JavaScript language. By using the DOM, we can get the entire input values from the form, when we click the event handling attribute “onclick” the function will be called and then post into corresponding PHP page. Here we are using the same PHP page for verifying the submitted input values.

Program:

<html>
<head>
<script>
function myFunction()
{
document.getElementById(“myForm”).submit();
}
</script>
</head>
<body>
<form method=”post” action=”Without_button.php” id=”myForm”>
<input type=”text” name=”name” /><br><br>
<input type=”text” name=”mobile” /><br><br>
<input type=”text” name=”age” /><br><br>
</form>
<div onclick=”myFunction()>Click me</div>
</body>
</html>

<?php
$x=””;
$y=””;
$z=””;
if(!empty($_POST[‘name‘]))
{
$x=$_POST[‘name‘];
echo $x. “<br>”;
}
if(!empty($_POST[‘mobile‘]))
{
$y=$_POST[‘mobile‘];
echo $y.”<br>”;
}
if(!empty($_POST[‘age‘]))
{
$z=$_POST[‘age‘];
echo $z.”<br>”;
}
?>

Hope, now you understand Data Submission without Submit button in PHP.  Let us have some more fun in upcoming posts.  Thanks a lot!