Passing POST data through form onto the same page

2019-07-27 15:16发布

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.

3条回答
做个烂人
2楼-- · 2019-07-27 15:50

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

查看更多
Melony?
3楼-- · 2019-07-27 15:51

sure. you can use XMLHttpRequest, and making it the easy way by using something like mootools or jquery.

I'll provide you an example of form submission with mootools. considering that your form has the id myForm

 document.addEvent('domready', function() {
     $('myForm').addEvent('submit', function(ev) {
    ev.stop();
    $('myForm').set('send', {
        onRequest: function(){
        },
        OnSuccess: function(response) {
              // do stuff with the response data
        }
            });
    $('myForm').send();
     });
 });
查看更多
虎瘦雄心在
4楼-- · 2019-07-27 16:07

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 :

查看更多
登录 后发表回答