Gooey
Gooey

Reputation: 4778

Send a $_POST request to another page without a form

I'm currently busy with PHP and thought of sending a POST request to another page without a form to do so. But how do you do this? I googled a bit and saw that cURL was used: is this the best way to go or can you do it (easy) without it?

I was thinking of making a small page where suggestions can be placed and you could decline / accept them. The suggestions are loaded from a (MySQL) database and presented along with an accept and decline button. If accept is clicked i would like to send the parameters to a page that accepts POST as in this way:

if(isset($_POST['name'] && isset($_POST['text'])) 
{
    // ...
}

I do know this can be done with $_GET, but i'd like to do it by $_POST for a change.

Upvotes: 1

Views: 4815

Answers (3)

Nadav S.
Nadav S.

Reputation: 2459

There are two acceptable methods:

  1. Sessions - Instead of using $_POST, use $_SESSION

    Reference: Manual

  2. AJAX - You can send POST requests without a form.

    Reference: AJAX tutorial / jQuery AJAX

Upvotes: 0

Florian Brinker
Florian Brinker

Reputation: 735

You can send Posts easily via Javascript (Ajax), see jQuery Ajax for examples. Or in PHP just use CURL, it is very easy to use.

If you need a curl-free alternative, use fopen like http://wezfurlong.org/blog/2006/nov/http-post-from-php-without-curl/

see also http://api.jquery.com/category/ajax/

Upvotes: 0

Nemanja
Nemanja

Reputation: 1535

Use jQuery to do a post request. More information can be found here.

An example would be:

$.post('ajax/test.html', function(data) {
  $('.result').html(data);
});

If you have difficulty implementing, feel free to ask further.

Upvotes: 2

Related Questions