programminghead Logo

How to Link Submit Button to another Page in PHP

To link Submit Button to another Page in PHP we can Use HTML's form's action Attribute. Where we can Specify the Target Page / Another where we want our Form data to be Submitted. If you don't want to Submit Form data to another page, Then scroll Down to see other methods to Link Submit Button to another Page in PHP.

Link Submit Button to another Page in PHP : Example


 <html>
  <body>
  
    <form action="/submit-page.php" method="POST">
      First name: <input type="text" name="firstN"><br/>
      Last name: <input type="text" name="lastN"><br/>
      <input type="submit"><br/>
      <button type="submit" formtarget="_blank">Submit to a new window</button>
    </form>
   
  </body>
 </html>

Results :

First name:
Last name:


HTML Form tag <form> used for Getting and Submitting Form Data from Users. Where Data Collected through Input Boxes input type="text", Check Boxes input type="checkbox", Text fields input type="textarea", Radio Buttons input type="radio" and Many more HTML Form Elements.

HTML form's Action Attribute defined targeted path where we want to Send out Form data. This Action method allows us to Link Submit Button to another Page in PHP.

HTML Form's method attribute Specifies how To send form data to Another Page. Where we Can use POST or GET method inside HTML Form's Method Attribute.

HTML Button attributes allows us to Add a Button inside HTML Document, So user Can click on that Button to Submit form data.
Where we have 2 Methods to Add Submit buttons in HTML,

Method 1: <input type="submit"/>
in this Input tyoe="submit" method, we'll have a Submit button which will Summit Given data to Given file when users Clicks on it.

Method 2 : <button type="submit">Submit</button>
This Method Works Exactly the Same as First Method, But in this Method we are using HTML's button Tag instead of HTML's input Tag.

If you want to Link Submit Button to another Page in PHP using Links insted of HTML Forms then We can use HTML's Anchor tag AKA <a>...</a> Tags. These tag of HTML Allows users to Redirect to an Another page on Click.
We just have to have to Define/Create that button inside the Anchor tags.
By using Achor tag's SRC attribute we can define another page's path of that page which we want our HTML Button link to.
We don't Always have to use Achor tag to redirect users to another page. We also us use JavaScript onClick Event or HTML Forms to Redirect or POST Data to another file. You can (Scroll Down to use another method)

Link Submit Button to another Page in PHP : Example


 <html>
  <body>
  
   <a href="home.html">
     <button> HOME BUTTON </button>
   </a>
   
   <a href="#">
     <input type="submit" value="Reload BUTTON"/>
   </a>
   
   <button>Simple BUTTON (Without Links)</button>
   
  </body>
 </html>

Results :


How to Link Submit Button to another Page in PHP : Image

The method used in the Previous Example will Tag user to another page on and displays another page's Content on the Same Window of the Browser. But what if we want our user to visit another page in another window without replacing the correct web-page's data. Then we can use Anchor tag's Target attribute to open page's in new, Parent, Current or inside a Pop-up window.

HTML Link Target Attribute :

When we click on the HTML Links, the linked web-page loads on the same page. but there is Target Attribute who gives us freedom to Perform Different Tasks like . Link opens in new tab. small/Big pop-up etc.

_blank :

Opens a new black tab in your Browser to load your Linked Web-Page.



<a href="test.html" target="_blank"> click me </a>	

_self :

This is default HTML Link Target, It Opens a your Linked Web-Page in the same Browser Window.



<a href="test.html" target="_self"> click me </a>	

_parent :

Opens parent links in a one Browser window inside Different Frames.



<a href="test.html" target="_parent"> click me </a>	

_top :

Opens a your Linked Web-Page on the Entire Browser window



<a href="test.html" target="_top"> click me </a>	

<html>
<head>
	<title>Bookmark/Goto Link</title>
	<style type="text/css">
		a:hover{
			background-color: red;
			text-decoration: underline;
			color: white;
		}
		#hideLink:hover{
			opacity: 0.5;
		}
	</style>
</head>
<body>
	<a href="test.html" target="_blank">new-tab Link</a><br/>
	<a href="test.html" target="_self">Default Link</a><br/>	
	<a href="test.html" target="_top">Top Link</a><br/>
	<a href="#">Empty Link</a><br/>	
</body>
</html>	

Result :


Link Page using JavaScript OnClick Method

JavaScript OnClick method allow us to redirect user to linked page on a Click.
For taht we just Have to create a JavaScript function and call that Function using HTML onclick attribute.
Here we are using a JavaScript function where we are going to use JavaScript window.location.href method to define Location of Another page. And JavaScript function only runs on function calling. So out Button will avoke/Call the function and "window.location.href = "path" will redect user to given Location.

Link Page using JavaScript : Example


 <html>
  <body>
      
   <button onClick="myfunction()">click me</button>

   <script type="text/javascript">
     function myfunction() {
       window.location.href = "mywebpage.html";
     }
   </script>
  </body>
 </html>	

Results :

Linking files for HTML Form's Data Submission :

This method of linking or Redirecting Users not used for Linking Users to another page on button click.
This method actually used for POSTing user's form Data to another page. Like user's name,address,age,phone numbers etc.
But still, here we have to link another page where Entered data going to be POST.
Here we use the HTML Form's action method. Which will take the path for another file (Mostly .php file).

Linking files for HTML Form's Data Submission : Example


 <html>
  <body>
  
   <form action="data.php" method="POST">
     <input type="text" name="userName"/>
     <input type="password" name="Password"/>
     <input type="submit">
   </form>
   
  </body>
 </html>	

Questions :

how to link submit button to another page in php

ANS :
PHP is a Server script language. so all the PHP element executed on the server and the final result will display on the Browser.
The button click event is not possible in the case of pure PHP program.

But if we use HTML inside PHP file this can be possible.
For using HTML inside PHP file we have two ways:
Use HTML Tags out side the PHP's starting and Closing tags or use HTML tags/ELements inside PHP's echo event.

first Method :


<?php
	//php data
?>
 <html>
  <body>
   <a href="page.html"><button>click me</button></a>
  </body>
 </html>

2nd Method


 <?php
	//php data
	echo '<a href="page.html"><button>click me</button></a>';
 ?>	

submit button redirect to another page html

ANS :
The process of linking HTML Element will be the same. Just we have to use Submit buttons at the Place of Normal Button.
Both buttons Work the same. But Way of declaring those button is little Different.
At the case of HTML Buttons, we use button's starting and closing tags.
<button>...</button>
But in the case of inserting the Submit button, we have to use HTML's Input element for that.

first Method :


 <html>
  <body>
   <a href="page.html">
    <input type="submit"/>
   </a>
  </body>
 </html>

Comments

Write to Us

Captcha