After refreshing, a blank page appears when using the HTML POST method

After conducting a test using an HTML form with the POST method, I encountered an unexpected outcome. The setup involved two HTML pages hosted on an Apache server (with PHP already installed): post.html and target.html. Below are the code snippets for these pages:

post.html (compliance with standard)

<div style="text-align: center">
   <form method="POST" action="target.html">
      <input type="text" name="testname" value="sometext" />
      <input type="submit" value="submit" />
    </form>
</div

and target.html:

<html>
  <head>
  </head>
  <body>
    <h1>Target page</h1>
  </body>
</html>

Upon entering data in the form on the post.html page and clicking the submit button, I was directed to the target.html page. However, upon refreshing the target.html page, it initially displayed as blank. Only after a second refresh did it return to its normal state.

This behavior raised questions for me as I noticed that when using a PHP page (e.g., target.php) instead of an HTML file as the target, the content remained intact even after multiple refreshes. I would appreciate any insights or explanations regarding this issue. Thank you.

Answer №1

It appears that the issue is related to your browser. I have experienced the same problem on a Mac using Safari. After submitting content on certain pages, the page freezes momentarily, but a simple refresh resolves the issue.

From my perspective, this does not seem to be a coding issue.

Answer №2

One limitation is the inability to transfer input from an HTML file to another HTML file. To resolve this issue, ensure that your target.html is converted to a PHP file named target.php, and insert the following code within it:

<?php
var_dump($_POST); // This function will display the entered text along with its data type, pausing the code execution. Any subsequent code will not be executed.
echo $_POST['testname'];
?>

Furthermore, revise the form action in your code by replacing target.html with target.php.

Answer №3

Let's start by revising your post.html content:

<div style="text-align: center;"> <!-- Added a semicolon after 'center' -->
   <form method="POST" action="target.html">
      <input type="text" name="testname" value="sometext" />
      <input type="submit" value="submit" />
    </form>
</div>

It might not make much of a difference, but it's good practice to end all your styles with a semicolon;

Overall, everything seems to be in order. Perhaps there was just a glitch during the page refreshes.

Answer №4

To save your form page in PHP, simply add the PHP script to the same page. Here is an example for you to try. Remember to save the file with a .php extension.

<?php $testname = $_Post['testname'];
echo $testname ?>

<div style="text-align: center">
    <form method="POST" action="">
        <input type="text" name="testname" value="sometext" />
        <input type="submit" value="submit" />
    </form>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unable to display <iframe> containing a YouTube video on Mozilla Firefox page

I have included an <iframe> in my webpage to display videos from YouTube, but I am facing an issue with Mozilla Firefox. In Chrome, IE, and Edge, the videos display correctly using the following code: <iframe src="http://www.youtube.com/v/DNLh8p ...

Unexpected problem with redrawing HTML application in Android WebView

I created a basic nixie clock app using HTML and wrapped it in a WebView for use on Android. It consists of one HTML file, a JS file, a CSS file, and ten digit images. After a few hours, I noticed stripes appearing in the center of the screen where the an ...

Exploring the capabilities of HTML5 canvas and integrating it with Selenium using Python

I have been working on testing a web server that is built using HTML5 with a canvas. While examining the source code for the login page, I noticed very minimal content. However, upon inspecting the element in Chrome, I discovered the following snippet: &l ...

Enhance web design with dynamic size pseudo elements using only CSS, no

Before the title, I've added a pseudo element with a slanted background. When the title is wrapped, it increases in height. I've been attempting to make the pseudo element adjust to the title's height, but haven't succeeded yet. I&apos ...

PHP - Adjusting the 'for' loop test counter to iterate based on the quantity of entries available

I am currently in the process of updating the database with specific values by using a for loop to iterate over each entry. However, I have limited it to only 6 iterations as seen below. for ($ind = 0; $ind <6; $ind++ ) Is there a way to make it loop ...

Tips for executing a Python function from JavaScript, receiving input from an HTML text box

Currently, I am facing an issue with passing input from an HTML text box to a JavaScript variable. Once the input is stored in the JavaScript variable, it needs to be passed to a Python function for execution. Can someone provide assistance with this pro ...

How to place a child <div> within a parent <div> that is fixed on the page

I am currently working on creating a modal window using HTML/CSS. My goal is to have the modal window fixed in position relative to the browser window, with a white background. Inside the modal, there will be an image at the top and a div element at the bo ...

Learn how to create a PHP activity feed that functions like Facebook, and discover the best methods for converting JSON responses into HTML

We are currently working on a website that functions similarly to Facebook, specifically focusing on the activity feed. To load the user's activity feed, we use AJAX to send a request to a PHP file which then processes the logic and returns the values ...

Anchor tags created using JQuery will remain on the same page without redirecting

Presented below is the code I have utilized to construct the anchor tag along with its content. $('div#right-slide').html("<a href=\"http://www.XXXXXXXXXXXX.info/limited-specials/\" ><h1 id=\"specials\">Click Here ...

Angular list with a repeating group of radio buttons

I have a set of 'options', which consists of the following: {Id: 1, Label: "option 1"}, {Id: 2, Label: "option 2"} Additionally, I have a list of 'products' structured as follows: {Id: 1, Name: "Name 1", Recommend: options[0]}, {Id: ...

Image Not Displayed on Page

I am facing an issue where I have a div class 'breadcam_bg' with an image url, but the image is not being displayed on the page even though the console detects the div. html <div class="bradcam_area breadcam_bg"> This div! & ...

Switch between different content sections using a button in a Bootstrap tab-pane

Here is the code snippet I am currently working with: <!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Example</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-s ...

storing the output of print_r in a variable

When using PHP, I've mastered: print_r($var); However, one thing that stumps me (or at least I haven't figured out yet) is: $var_info = print_r($var); My goal is to store the output of a print_r function in a variable. Any ideas on how to ach ...

Incorporating JSON data into an HTML table

Looking to populate an HTML table with JSON data, but struggling with parsing and appending the data correctly. Can anyone provide guidance or assistance? <!DOCTYPE html> <html> <head> <title>JSON Demo</title> < ...

Transform the parent-child array into an unordered list using list items

Extracting and organizing username (child) and referral (parent) records from the database are done using the following code: $sql = "SELECT username, referral FROM acc_status"; $q = $conn->prepare($sql); $q->execute(array()); ...

Iterating over images and displaying them in Laravel's blade templating engine, updating outdated Angular code

Currently, I am in the process of transitioning an Angular repeat function used for displaying images on our website (built with Laravel). The goal is to eliminate Angular completely and handle everything using Laravel loops in the blade template. I have ...

The presence of the `class` attribute on the `td` element

Is there a reason why the rows with the "odd" td class in this script do not toggle to blue like the rows without the "odd" class? EDIT: When you click on a row (tr), it is supposed to turn blue (.hltclick) and return to its original color when clicked ag ...

Combining rewrites with various origins within location blocks

I'm finding it difficult to figure out how to manage rewrites for PHP scripts when the location blocks that handle the rewrites have different root directories. Let me give you a simple example. My catch-all front controller needs to be in the web ro ...

Sending arguments from JavaScript to PHP via ajax

I am facing a challenge where I need to send a JavaScript variable to a PHP function. While I was successful in doing this with hard-coded values, I'm struggling when it comes to using variables. Here's an example of what worked for me: <butt ...

Ways to show the content of a variable in JSON format

Looking for a solution... { "status":"ok", "message-type":"funder-list", "message-version":"1.0.0", "message":{ "items-per-page":20, "query":{ ...