passing data from an html page to a php page and preserving it

Discussion in 'PHP' started by jimdickens, Oct 6, 2009.

  1. #1
    I have an html page that gathers data without problems.

    The form tag on that page is

    <form id="maininput" name="maininput" action='orderpage.php' method='post' enctype='multipart/form-data' >

    That passes data to orderpage.php perfectly because I can see it when I use print_r() to display it.

    In the header, I then assign the POST variables to php variables using statements like:

    if (!isset($firstname)) {$firstname = $_POST['firstname'];}

    After assigning the variables to php variables, I display the variables in another form on this page with the following tag:

    <form name="readyforPayPal" onSubmit="return checkAgreement();" method="POST">

    checkAgreement is a Javascript function that makes sure that the customer has checked a checkbox on this page.

    The submit tag is

    <input type='submit' id="gotopaypal" name='gotopaypal' value="Submit" />

    Everything is fine and all data is available both in $_POST and in the php variables until I click submit.

    After I click submit, all of the variables lose their value and become unset.

    Why is this happening? or better question: How do I preserve the variables and still require the user to verify that their data is correct and that they want to proceed with the order.

    Thank you for any help
     
    jimdickens, Oct 6, 2009 IP
  2. prasanthmj

    prasanthmj Member

    Messages:
    62
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    45
    #2
    prasanthmj, Oct 6, 2009 IP
  3. Bill_Stanbrook

    Bill_Stanbrook Well-Known Member

    Messages:
    1,046
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    150
    #3
    Another option is to add a value="" attribute to your form fields, and use server-side scripting to rewrite the page to insert the data you want to be persistent, into the value field (eg. value="{insertion-point}" becomes value="inserted_value").

    Use a template for the form, with unique find-and-replace target text inserted in place of the persistent data, and then use 'str_replace' to replace the target text with your persistent data values.

    Alternatively, use a standardized target text string for all your insertion points, and 'explode' the form template into an array, using the target text as the separator string for the 'explode' function. You'll end up with your form template code broken up into sections, which are stored in whatever array you used for the 'explode' function. You then wrap the sections around the values you wish to insert into the form (eg. $form_code = $section[0] . $_REQUEST['$value1'] . $section[1] . $_REQUEST['$value2'] . $section[2] . $_REQUEST['$value3'] . $section[3]; ). This method can be useful where you need to insert the values in parallel.
     
    Last edited: Oct 6, 2009
    Bill_Stanbrook, Oct 6, 2009 IP
  4. jimdickens

    jimdickens Guest

    Messages:
    14
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thank you so much. You gave me the right path to follow. However, instead of session_register, I used the following at the top of the page:

    session_start();
    foreach ($_POST as $key => $value){
    $_SESSION[$key] = $value;
    }

    That page you gave me suggest using session_register(). When I looked it up on PHP.NET, I found the following warning message on the page about session_register():

    This function (talking about session_register) has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 6.0.0. Relying on this feature is highly discouraged.

    That may cause a lot of people pain later on

    Thanks again
     
    jimdickens, Oct 7, 2009 IP