Jump to content

[SOLVED] How to remember POST variabe from html


etxnreg

Recommended Posts

Hi,

I am a beginner in this area, and need help with following.

I have  lot of POST variables for the php script.

Therefor I have created more than one HTML page with a next button between them.

The problem is when I in the last HTML page request the php script only the POST variables from the last page are transferred to the php script.

How should I do so all variables are transferred to the php script?

 

BR Niklas?

 

Link to comment
Share on other sites

Save the information between requests.

 

session_start();
if (!empty($_POST)) {
    if (!isset($_POST['wizard_finished'])) { // preferably only present on the last step
        $_SESSION['_POST'] = array_merge($_SESSION['_POST'], $_POST);
    } else {
        //wizard finished
        $_POST = $_SESSION['_POST'];
        //process as if it were one-page request
    }
}

Link to comment
Share on other sites

Hi,

Thanks for the quick answer.

I need some more hints how actually I get the input box value copy to the session variable when next putton is pushed.

My code is as following:

<?php

session_start();

?>

<html>

<head>

</head>

 

<body>

 

<form name="form1" method="POST" action="interface.php" style="margin:0px">

<input name="test1" value="test1" type="text" style="position:absolute;width:200px;left:18px;top:108px;z-index:0">

<input name="formbutton1" type="submit" value="next" style="position:absolute;left:72px;top:202px;z-index:1">

<?php

$_SESSION['test1']=$_POST[test1];  ########## This line probably wrong##############

?>

</form>

 

</body>

</html>

 

 

 

Thanks Niklas

Link to comment
Share on other sites

for much easier debuggin why dont you separate your html codes from your php codes.

 

<?php
session_start();

extract($_POST); // extract $_POST array so you wont be type $_POST always

$_SESSION['test1']=$test1;


?>
<html>
<head>
</head>

<body>

<form name="form1" method="POST" action="interface.php" style="margin:0px">
<input name="test1" value="test1" type="text" style="position:absolute;width:200px;left:18px;top:108px;z-index:0">
<input name="formbutton1" type="submit" value="next" style="position:absolute;left:72px;top:202px;z-index:1">

</form>

</body>
</html>

Link to comment
Share on other sites

Hi,

I have now separated the php code from the HTML.

Unfortunately I have still problem to transfer the input box value to another php script.

if I change following line

$_SESSION['test1']=$test1;

to

$_SESSION['test1']=hello

 

the value is transferred to the next php script.

It seems to be something with the input box.

Any suggestions?

 

BR Niklas

 

Link to comment
Share on other sites

Save the information between requests.

 

session_start();
if (!empty($_POST)) {
    if (!isset($_POST['wizard_finished'])) { // preferably only present on the last step
        $_SESSION['_POST'] = array_merge($_SESSION['_POST'], $_POST);
    } else {
        //wizard finished
        $_POST = $_SESSION['_POST'];
        //process as if it were one-page request
    }
}

 

This code isn't entirely correct, it will delete any post values on the last page:

$_POST = array_merge($_SESSION['_POST'] /*stored values*/, $_POST /*post values from the last page*/);

 

Should fix this problem.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.