Help please with a form

Hello all you smart people. I’m hoping you can help me with a problem. I have been asked to help update a web site that is using MODX. But there is a bunch of custom PHP pages, that to this point I have been able to update with little help by pouring over the code and making changes.

Now for my issue: I want to pass user info from a form to the next page that will be filled in with that info. An example would be the users name, address, etc.

At the beginning of the page with the initial form I added:

**<?php**
**// Start the session**
**session_start();**

And what already existed was this:

**if (isset($_POST['fname']) && $_POST['fname']!=''){ $fname = mysql_escape_string($_POST['fname']); }else { $error .='First Name<br />'; }**

With several other lines with additional user information below that line for adress, city, state, etc. My question is, how to I pass that information onto the next page? How do I create a variable that can then be called on the next page. Most likely adding to the above line and passing [‘fname’] to the second page and displaying it.

Thank you all in advance,
Mark

You already have the session started, add it to that.

page 1

<?php
session_start();

$_SESSION['data'] = $_POST;

page 2

<?php
session_start();
echo '<pre>';
print_r($_SESSION);
echo '</pre>';

I’m not sure I understand, as I am a newbie on the actual php coding part of this.

The actual page is here:
http://nyadtcp.org/conferences/treatment-courts-2020-vision-improving-health,-justice-and-communities/attendee-registration1.html

Once a user submits the form, it jumps to here:
http://nyadtcp.org/assets/registration-forms/invoice.php

Which I want to populate with the users information, date, etc.

When a form is submitted and the method is post, the values are available in the $_POST global array for use on the processing page.

So if I add the lines at the beginning of the their perspective pages that you replied to above, I should have the data needed?

Thank you,
Mark

Actually if you have a form on one page and send the data on the form to a processing page, it will already be in the global array.

You can test this with the following.
page 1

<form method='post' action='test2.php'>
    <p>First Name<input type='text' name='first_name'></p>
    <p>Last Name<input type='text' name='last_name'></p>
    <p><input type='submit' value='Test me'></p>
</form>

test2.php

<p>We prefilled this out for you</p>
<form method='post'>
    <p>First Name<input type='text' name='first_name' value='<?php if(isset($_POST['first_name']) echo htmlentities($_POST['first_name']); ?>'></p>
    <p>Last Name<input type='text' name='last_name' value='<?php if(isset($_POST['last_name']) echo htmlentities($_POST['last_name']); ?>'></p>
    <p>Email<input type='email' name='email_address'></p>
    <p>Phone #<input type='phone' name='phone_num'></p>
    <p><input type='submit'></p>
</form>

The example is not a complete html document, you will have to add that, but this will show you what I think you are asking for.

test2.php produced an error:

Parse error : syntax error, unexpected ‘echo’ (T_ECHO) in /home/jusbarry/public_html/assets/test/test2.php on line 3

Opps, doing this without code highlighting!

<p>We prefilled this out for you</p>
<form method='post'>
    <p>First Name<input type='text' name='first_name' value='<?php if(isset($_POST['first_name'])) echo htmlentities($_POST['first_name']); ?>'></p>
    <p>Last Name<input type='text' name='last_name' value='<?php if(isset($_POST['last_name'])) echo htmlentities($_POST['last_name']); ?>'></p>
    <p>Email<input type='email' name='email_address'></p>
    <p>Phone #<input type='phone' name='phone_num'></p>
    <p><input type='submit'></p>
</form>

Ok, while that worked in test, I don’t think it is what I’m trying to accomplish. Let me start over.

A form is presented to the user. Once they submit the form, the data is sent to a sql database. An email is sent to the user is the form of plain text, acknowledging all of the info. I’m trying to popup an invoice that I created in HTML, but want to inject the basic data from the initial form into the HTML page. I may have sent the wrong line initially. I believe the is where the data is processed to go into the sql database.

This line is the actual line that the user fills in on the form:

First Name

So my question is: do I need to use a $_session to bring the variable $fname over to page 2 (the invoice)? Can it be pulled from the database entry?

Here is the page that the info needs to be pulled into:
http://nyadtcp.org/assets/registration-forms/invoice.php

Thanks again for your patience.

Alright. So they are still on the site, not coming back to it, correct?

Correct. You can test the form (see my second posting) as the site is not live yet. Feel free to try it and you’ll see what it is trying to accomplish.

Then, you will want to utilize the session variable. It won’t work on an html extension file, but you can do a similar thing that I showed previously with minor modifications.

page 1

<?php
session_start();
?>
<form method='post' action='test2.php'>
    <p>First Name<input type='text' name='first_name'></p>
    <p>Last Name<input type='text' name='last_name'></p>
    <p><input type='submit' value='Test me'></p>
</form>

test2.php

<?php
session_start();

$_SESSION = $_POST;
// your processing page

Your popup form

<?php
session_start();
?>
<p>We prefilled this out for you</p>
<form method='post'>
    <p>First Name<input type='text' name='first_name' value='<?php if(isset($_SESSION['first_name'])) echo htmlentities($_SESSION['first_name']); ?>'></p>
    <p>Last Name<input type='text' name='last_name' value='<?php if(isset($_SESSION['last_name'])) echo htmlentities($_SESSION['last_name']); ?>'></p>
    <p>Email<input type='email' name='email_address'></p>
    <p>Phone #<input type='phone' name='phone_num'></p>
    <p><input type='submit'></p>
</form>

It still isn’t working as intended. The html page actually has a php include file that makes up the form. Then the popup page has some php code, pretty much the date and the php session start at the top. I don’t want to open another form on the popup invoice. I just want to have the highlighted info placed on the page.image

Since this web site thinks some of my posts are spam the point may not be getting across. So here goes another stab at help:

I added to the top of the php form:

<?php
session_start();

Then added this to the Invoice page:

<?php
session_start();

In the body (3 different attempts to get the information to display):

<p><?php echo ['fname']; ?><br />
     <?php echo $fname; ?> <br />
    <?php ($_POST['fname']); ?>
     State Zip
  </p>

Output displayed:

Array
                      (blank line)
                      (blank line
State Zip

So “Array” is coming from someplace, but the actual data isn’t displaying. It should be the variable fname from the form.

Thank you

try

session_start();
echo '<pre>';
print_r($_GET);
print_r($_POST);
print_r($_SESSION);
print_r($_SERVER);
echo '</pre>';

That spit out a lot of information. If I put that on the form page, all the input fields I’m looking for are there. If I put it on the destination page, it isn’t. I only get mostly server information. Here are the first few lines:

Array
(
)
Array
(
)
Array
(
    [CONTEXT_DOCUMENT_ROOT] => /home/jusbarry/public_html
    [CONTEXT_PREFIX] => 
    [DOCUMENT_ROOT] => /home/jusbarry/public_html
    [GATEWAY_INTERFACE] => CGI/1.1
    [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    [HTTP_ACCEPT_ENCODING] => gzip, deflate
    [HTTP_ACCEPT_LANGUAGE] => en-us
    [HTTP_CONNECTION] => keep-alive

So it appears that it’s not being sent to the destination from the form.

Thanks

Something else to note here:
There is another php page in the middle, that does some of the processing. So it goes like this:

php form > thank you > the page that is missing the array info

If i put the lines in to get the array info I get the following results:

php form will list all the variables
thank you page gets all the variables
invoice (target) page gets limited info (server, but no address, etc.)

So the “thank you” page somehow is stripping out the session variables.

So, the first form posts the data entered by the user.
The second form says thank you.
nothing is shown on the third page.

So, did you save the data into “Session” variables as Stonecypher mentioned? Posted data only goes to the next form, not any forms after that. If you saved it in the session array, use that one to display on the third form. Make sense?

So, the first example wont print anything ever. The second will, but only if that variable has a value assigned prior to using it. The last will only have a value if another form sent it directly to that specific page.

The post data needs to be added to the session on the page that processes the initial form. The data would then be available for all other pages that implement the session after processing.

Sponsor our Newsletter | Privacy Policy | Terms of Service