Logo - ProgrammingHead

How to Link Submit Button to Another Page in PHP

If you are wondering about, How to link submit button to another page using PHP. Then you have come to the Right Place.
Because In this Tutorial, we are going to Link Submit button to another page using PHP.
First of all, PHP is a Server Side Scripting Language. So we can't run Button Clicks Events using PHP but we can use HTML Anchor, Form or JavaScript inside PHP to Link One page with Another Page.

How to Link Submit Button to Another Page in PHP [Updated]

Method 1: Link Submit button to Another page using forms Tags in PHP

In HTML's Form tag we can Link submit Button to another page using HTML Form's Action Attribute.
Where we have to Write our File Path inside HTML form's action=”” attribute.
After that when the user clicks the Form Button, It will redirect that user to another page.

page1.php

<?php 
 echo '<form method="POST" action="page2.php">
    <input type="submit"/>
  </form>';
?>

Results

Link Submit button using Ancher Tags in PHP

We can use Anchor <a> tags to Link a Submit button to another page in PHP. We need to Write/Declare Submit button between Anchor <a>...</a> tag's Starting and Closing tags.
By using Anchor tag's href="" attribute we can give a Path where we want to Link our Submit Button.

page1.php

<?php
 echo '<a href="page2.html">
      <input type="submit"/>
  </a>';
?>

Results

Related Topics: How to Link Submit Button to Another Page in PHP [Updated]

Click on Titles below to reveal the Data

Link Submit button to Another page using JavaScript

If you don't want to use Form tag or Ancher tags to Link Submit button to another page in PHP then we can use JavaScript for that.
In JavaScript, we create a Function which will handle all the Data like Page Path where we want to Link our Submit Button.
The function name, By using that Function name we can call that function through HTML onClick attribute. Which we call the assigned
function and we can redirect our users from one page to another by clicking on the Submit Button.

index.html

<html>
<body>
 <input type="submit" onClick="myFunction()"/>
 <script>
  function myFunction() {
    window.location.href="page2.html";
  }
 </script>
</body>
</html>

Results