Passing POST data through form onto the same page

11,158

Solution 1

this if understand your question can be done many ways, eg using function based fillers. One way is to check if the form has been posted using $_POST or by checking for a hidden field $_POST['_submit']. this looks messy but shows basic way.

 <?php
  if (!isset($_POST['_submit'])) {
 ?> 

 <form action="post.php" method="post">
  <input type="submit" />
  <input name="somevalue" type="text" />
  <input name="_submit" type="hidden" value="_submit" />
</form>

<?php
 } else {
  echo htmlspecialchars($_POST['somevalue']);
 ?>

 <em></em>

 <?php } ? >

There are other things that you would still need to do to make this code production ready like uisng isset on fields your checking against else you will have losts of notices if people tamper with the form

Solution 2

Just let the action part empty

<form method="post" action="">
    <input name ="MyCustomInput" type="text" />
</form>

in order to call the input data within the page :

Share:
11,158
Truong
Author by

Truong

Updated on June 04, 2022

Comments

  • Truong
    Truong almost 2 years

    I have a rather complicated situation. Right now I have a form on a page that asks for my visitor's information. I have a script that allows me to take the visitors information and append it to a link.

    At first, I had a redirect.php that allowed me to append all the information to the link and used a header to send the user to their page.

    However, I was wondering if it is possible to send this form data into the same page AND display the users page at the same time.

    I'm hoping I make sense. Thanks a lot.