Greetings,
I am developing a website using WordPress and elementor. I have a form with the POST method on page1 which is redirecting the user to page2. How do I receive that data on page2 and display it in the H1 tag on the same page?
CodePudding user response:
Data submitted from a form with the method='post'
attribute can be accessed using the $_POST
superglobal. For example:
// page1.php
<form action='/page2.php' method='post'>
<input type='text' name='name' placeholder='Enter your name' />
<input type='submit' value='Send' />
</form>
// page2.php
<?php
$name = $_POST['name'] ?? 'World';
?>
<h1>
Hello, <?php echo $name; ?>
</h1>