sgt_johnny
sgt_johnny

Reputation: 329

Pass POST over to two pages?

I have the following pages (code fragments only)

Form.html

<form method="post" action="post.php">
<input type="text" name="text" placeholder="enter your custom text />
<input type="submit">
</form

post.php

....
some code here
....
header('Location: process.php');

process.php

on this page, the "text" input from form.html is needed.

My problem is now, how do i pass the input-post from the first page through process.php without loosing it?

i dont want to use a process.php?var=text_variable because my input can be a large html text, formated by the CKeditor plugin (a word-like text editor) and would result in something like this process.php?var=<html><table><td>customtext</td>......

How can i get this problem solved?

I would like to have a pure php solution and avoid js,jquery if that is possible.

Upvotes: 1

Views: 882

Answers (3)

Sam Katoozi
Sam Katoozi

Reputation: 59

If you don't want to use $_SESSION you can also make a form in the page and then send the data to the next page

<form method="POST" id="toprocess" action="process.php">
    <input type="hidden" name="text" value="<?php echo $_POST["text"]; ?>" />
</form>

<script>
document.getElementById("toprocess").submit();
</script>

or you can the submit the form part to whatever results in moving to another page.

Having said that using the $_SESSION is the easiest way to do this.

Upvotes: 1

Mouser
Mouser

Reputation: 13304

Either use $_SESSION or include process.php with a predefined var calling the post.

$var = $_POST['postvar'];
include process.php;

Process.php has echo $var; or you can write a function into process.php to which you can pass var.

Upvotes: 1

fpierrat
fpierrat

Reputation: 804

maybe the doc can help: http://php.net/manual/fr/httprequest.send.php

especially example #2:

$r = new HttpRequest('http://example.com/form.php', HttpRequest::METH_POST);
$r->setOptions(array('cookies' => array('lang' => 'de')));
$r->addPostFields(array('user' => 'mike', 'pass' => 's3c|r3t'));
$r->addPostFile('image', 'profile.jpg', 'image/jpeg');
try {
    echo $r->send()->getBody();
} catch (HttpException $ex) {
    echo $ex;
}

But I wouldn't use this heavy way where sessions are possible and much easier, see previous answer/comments. This is ok for instance if you want to call a pre-existing script awaiting post-data, if you can't (or don't want to) modify the called script. Or if there's no possible session (cross-domain call for instance).

Upvotes: 0

Related Questions