Forum Moderators: coopster

Message Too Old, No Replies

Pass data from one html form to another

         

Bella6

4:25 pm on Jan 15, 2004 (gmt 0)

10+ Year Member



Being a noob to PHP please forgive me if my question is basic.

I've created a 2 page application form in html. Once the person has completed the first page and submits, I send an email with the form data using a php which then redirects to a second .html page. Once the second page has been filled out, and the person click submit, a second php is run and I receive a second email with the data from the second page.

I need to be able to pass the person's last name from the first page to the second in order to know who has filled out the second page.

Is there a way to send data from one form to another through a php script?

Help!? :S

coopster

4:36 pm on Jan 15, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, Bella6!

The form information is available to your PHP script via the $_POST or $_GET superglobals. You can move information using PHP just as you would with any other form processing script. For example, sessions, cookies, or hidden <input> fields. For example, let's say your first page has a form processing script called page2.php. In that script, as you are building your HTML form, simply bury the value of the last name field from the POSTed data from page1 in your page2 <form> as follows:


<input type="hidden" name="lastname" value="<?php print $_POST['lastname'];?>" />

There are a number of ways to accomplish what you are expecting to do. You may want to dig in and find a tutorial or book to get you through the basics. Here are a couple of other threads to get you jump-started:

PHP Tutorial [php.net]

Php, Mysql, Apache, Netscape 4.78
how do i start my php adventure?
[webmasterworld.com]

new to programming
therefore new to PHP
[webmasterworld.com]

Bella6

4:49 pm on Jan 15, 2004 (gmt 0)

10+ Year Member



This is what my 1st PHP looks like (email.php). This is run when I click submit on my page1.html:

<?php
$email = $HTTP_POST_VARS[ContactEmail];
$mailto = "****@****.com";
$mailhead = "From: $email\n";
reset ($HTTP_POST_VARS);
$mailsubj = "Application Submission 1 of 2";
$mailbody = "NEW APPLICATION\n";
while (list ($key, $val) = each ($HTTP_POST_VARS))
{$mailbody .= "$key : $val\n";}
mail($mailto, $mailsubj, $mailbody, $mailhead);
header("Location: [domainname.com...]
exit;
?>

From what I understand, in page2.html, i need to add: <input type="hidden" name="lastname" value="<?php print $_POST['lastname'];?>" />

What do I need to add in my email.php file to get the data from page1.html?

Thanks!

coopster

5:07 pm on Jan 15, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Oh, I see what you are doing...

There are still a couple of ways to do this. One would be to append a query string to your redirected URL and make it a PHP parsed page:


header("Location: h**p://www.domainname.com/page2.php?lastname=" .
htmlentities [php.net]($HTTP_POST_VARS['lastname'])
);

...and in the page2.php you would add the code described earlier (except now it will be in the $_GET superglobal array, not the $_POST).

Another approach would be to mail the information off in

email.php
, then instead of redirecting, replace the header redirect with the HTML that you currently have in page2.php.

Either way, your choice. There's more than one way to do it!

Bella6

6:48 pm on Jan 15, 2004 (gmt 0)

10+ Year Member



Page2 isn't a .php file. It has to be an html file. Will you first option work with an html file?

These are the file:
page1.html, click submit, launches email.php and redirects to open page2.html

coopster

12:30 am on Jan 16, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>>I need to be able to pass the person's last name from the first page
>> to the second in order to know who has filled out the second page.
>>
>>Is there a way to send data from one form to another through a php script?

Yes, using PHP :) The data from the form has to put their dynamically in this case, correct? What I mean is that

lastname
is a variable whose data changes for each unique user that fills out the form. If you have a hard-coded html form for the second page, when they SUBMIT the second page, it will POST any <input> variables found in the <form>. How are you going to get the
lastname
variable into your form if it is standard html and not processed by a PHP parser?

I imagine you could use javascript somehow, but we are looking for a PHP solution. Am I misunderstanding your goal somehow?

Bella6

7:45 pm on Jan 16, 2004 (gmt 0)

10+ Year Member



Thanks for your help coopster.

The site that I'm working with uses SSI's, and to include these SSI's my main pages need to be .html pages. Unless, there is a way to modify the .htaccess file so that .php files are parsed as html.

I've got page1.html that has a form that the user fills out, which includes their last name as a unique identifier. Once the person click submit, email.php is run and send out an email with the details of the form on page1.html. In email.php, thre is a header that then redirects and opens up page2.html which is page 2 of the application form. If they choose to fill this out, then a second email is sent.

This would all work fine if I was able to save page2 as a .php file vs a .html file...but then my includes for my ssi's will not work.

Am I making any sense? If the solution is to simply hard code the second page and forget about the SSI's I will do so, but this is not a preferred option.

Sorry to be such a pain :S. I'll be sure to become a little more familiar with PHP after this project ;)

coopster

9:03 pm on Jan 16, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>>Unless, there is a way to modify the .htaccess file so that .php files are parsed as html.

There is a way to parse html as php [httpd.apache.org], but you may not need to do that. Read on...

>>This would all work fine if I was able to save page2 as a .php file vs a .html file...but then my includes for my ssi's will not work.

You can use PHP's include [php.net] function in place of your SSI statements. When a file is included, parsing drops out of PHP mode and into HTML mode at the beginning of the target file, and resumes again at the end. For example, let's say you have a SSI that is a top navigation bar in your html. With PHP, you simply include that file:


<html><head><title>Title</title></head><body>
<?php include("topnav.html");?>
<form>
<input type="hidden" name="lastname" value="<?php print $_POST['lastname'];?>" />
<!-- More HTML here -->
</form>
</body></html>

As long as this file was saved with a .php extension, PHP would parse it and give you what you want. Make sense?

BitBanger

9:10 pm on Jan 16, 2004 (gmt 0)

10+ Year Member



This may not be the best way to do this, but by adding:

AddType application/x-httpd-php .php .html

to your .htaccess file, .html will now be parsed for php.

Bella6

9:48 pm on Jan 16, 2004 (gmt 0)

10+ Year Member



Coopster - I'm going to try that out..maybe that will the answer to my problems!

BitBanger - I came across that..but have read in places that if i use that in my .htacess file, this statement will no longer work
AddType text/x-server-parsed-html .html
(i use this for my SSI).

tks.