开发者

How to use Post method without a Form

开发者 https://www.devze.com 2023-01-30 22:01 出处:网络
I am that kind that spends more time looking for bugs in开发者_如何学Go web projects and correct them, but I still have one question about the use of the GET and POST method

I am that kind that spends more time looking for bugs in开发者_如何学Go web projects and correct them, but I still have one question about the use of the GET and POST method

To summarize , I often use the GET method for queries that may be coming from links or simple buttons example :

<a href="example.php?n=2030004">Click me</a>

and for forms (signup,login, or comment) I use the post method. but the question is:

sometimes (Multi-steps signup for e.g), I may need to pass the info collected from the form in page 1 to a page 2 (where the user can find a captcha for e.g). in order to send them to the database if the captcha test is Okey. But the question is , how to pass those info to a next page via a POST method without using a hidden form? Do I need to recreate a POST method from scratch with a socket?

thank you


You can use JavaScript (jQuery):

First u need to load jQuery ( using google as host or you download it):

<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.js"></script>

Then...

    <script type="text/javascript">
    $(document).ready(function() {
         $('#Link').click(function() {
              $.post("example.php", { n: "203000"} );
         });
    });
    </script>

<a id="Link" href="#">Click me</a>

Edit:

after that save it in the SESSION in example.php

$ _SESSION['N'] = (int) $_POST['n'];

When this value will be stored on the server side. And tied to the client session, until he closes browser or that it set the time for that session on the server side runs out.

Edit2: There is also another possibility to post requst, yes .. But I do not like this method myself ... And here is the form used, something the OP did not want.

<form name="myform" action="example.php" method="POST">
    <input type="hidden" name="n" value="203000">
       <a id="Link" onclick="document.myform.submit()" href="#">Click me</a>
</form>


Use sessions to store the data until you submit them: http://de.php.net/manual/en/intro.session.php. Using sessions has a big advantage, once you have verified the data you can store it.

Always keep in mind that users may manipulate POST requests!


If the problem is to pass info between pages like in a multi-step form you should use session (if you are using PHP). By the way for send a POST request without form you need to use CURL like in this example


The statement is a HTML language statement used by a browser to initiate a POST/GET data relation. The Browser is the execution environment.

You can use other languages (and their execution environment) like Java, Java Script, C#, etc. to initiate HTTP POST/GET data relations.


Sorry if I'm not understanding you correctly, but from what I'm reading, you want to access form data entered on page 1 (using a form with a post method) on page 2? If so, use the $_POST autoglobal array. For example, $nameOnPage2 = $_POST['nameFromPage1']. You don't have to create a form on the second page for this.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号