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

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.

index.php

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

Link Submit button using Ancher Tags in PHP

We can use Anchor tags to Link a Submit button to another page in PHP. We need to Write/Declare Submit button between Anchor 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.

index.php

<?php
 echo '<a href="http://programminghead.com">
      <input type="submit"/>
  </a>';
?>
Ad

Need a Personal Tutor?

I am here to help you with your Programming journey. HTML, CSS, JavaScript, ReactJS, NextJS, C, C++, C#, SQL and more.

Less then 5$/hSee Plans100% Free Trial + Money Back Guaranty

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="http://programminghead.com";
  }
 </script>
</body>
</html>

FAQs about : How to Link Submit Button to Another Page in PHP

Submit button redirect to another page HTML

To redirect users to another page using Submit button we can use HTML’s Ancher tag or Form tags for that.
In Anchor tags and Form Tags, we need to Write/Declare our Submit button between Anchor tags or Form Tags.
Which will make our Submit button Clickable. And by using Anchor and Form tag’s href attribute we can Specify the Path where we want our users to redirect after clicking the Submit Button.

index.html [Redirect using HTML Form Tags]

<form action="nextpage.php" method="POST">
  <input type="submit"/>
</form>

index.html [Redirect using HTML Anchor Tags]

<a href="http://programminghead.com">
  <button>Click Me</button>
</a>

How to make a button or one page link to another page in HTML using the button

Just write/Declare your HTML Button inside HTML Anchor tags . Anchor tags will make our HTML Buttons Clickable and after that, you can use Anchor tag’s href attribute to give the Path to your Button.

index.html

<a href="http://programminghead.com">
  <button>Click Me</button>
</a>
Ad

Need a Personal Tutor?

I am here to help you with your Programming journey. HTML, CSS, JavaScript, ReactJS, NextJS, C, C++, C#, SQL and more.

Less then 5$/hSee Plans100% Free Trial + Money Back Guaranty

How to handle multiple submit buttons in HTML forms

In HTML Forms all the Buttons inside Form Tags will work like a Submit button. Which will redirect users to the same page (Which we have declared inside HTML form’s action attribute)
If you want to Handle multiple Submit buttons then you can use Multiple Form tags with multiple Page Path.
or you can use Anchor tags instead of Form tags to redirect Users using multiple submit buttons in HTML

Link submit button using JavaScript

index.html

<html>
<body>
  <input type="submit" id="submitBtn"/>
  <script>
 document.getElementById("submitBtn").addEventListener("click", myFunction);
function myFunction() {
  window.location.href="http://programminghead.com";
}
  </script>
</body>
</html>

JavaScript windows.location allows us to redirect our users to another page on a single click.
We just need to add a Click event inside our JavaScript. Which will run when user Invoke the Click Event by clicking the Submit button.
JQuery .click() method makes this Button linking process more simple and Easy. But for that you have to Download the JQuery Library file from the Internet.

Ad

Need a Personal Tutor?

I am here to help you with your Programming journey. HTML, CSS, JavaScript, ReactJS, NextJS, C, C++, C#, SQL and more.

Less then 5$/hSee Plans100% Free Trial + Money Back Guaranty
Logo