0

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?

  • Your question is not quite clear – Innovin Sep 27 '22 at 20:31
  • Does this answer your question? [How to pass data between wordpress pages](https://stackoverflow.com/questions/9127054/how-to-pass-data-between-wordpress-pages) You might also search WordPress Stack Exchange for solutions: https://wordpress.stackexchange.com/ – Yogi Sep 27 '22 at 20:34
  • I want the display the data I have received from post method on html heading tag – Utaiba Naqshbandi Sep 27 '22 at 20:34
  • @Yogi no, because I am able to send data but I just cannot figure out how to receive it on page2 and show in html heading – Utaiba Naqshbandi Sep 27 '22 at 20:36
  • The solutions I've seen usually save the form data to session (php $_SESSION[ ]) which can then be reused on other pages. See this related question: [Storing Form Data as a Session Variable](https://stackoverflow.com/questions/3791414/storing-form-data-as-a-session-variable) – Yogi Sep 27 '22 at 20:48

1 Answers1

1

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>
DannyXCII
  • 888
  • 4
  • 12
  • Thank you, but how can I execute this code in elementor page builder in wordpress – Utaiba Naqshbandi Sep 27 '22 at 21:58
  • Ideally you could edit the theme files (make a child theme if it's not your own custom theme) - alternatively this looks like it could be a good plugin: [PHP Code Widget](https://wordpress.org/plugins/php-code-widget/) - I haven't used WordPress for a couple of years now at least so not sure if there are better options – DannyXCII Sep 27 '22 at 22:05