How can data from a text field be preserved and displayed on a new page in PHP?
To preserve and display data from a text field on a new page in PHP, you can use the $_POST superglobal to retrieve the data submitted from the form on the previous page. You can then store this data in a session variable and access it on the new page to display the preserved text field data.
<?php
session_start();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$_SESSION['text_field_data'] = $_POST['text_field'];
header("Location: new_page.php");
exit();
}
?>
```
On the new_page.php:
```php
<?php
session_start();
if (isset($_SESSION['text_field_data'])) {
$text_field_data = $_SESSION['text_field_data'];
echo "Preserved text field data: " . $text_field_data;
} else {
echo "No text field data preserved.";
}
?>