Page 1 of 1

working with multible forms ?

Posted: Mon Nov 04, 2002 3:27 pm
by terji
I need some help working with a form containing a form :?
I'm coding the typical compose email gui. After entering e-mail, title and the message itself I want to give the user the option to attach up to several files. When pressing [attach file] the user is directed to an "upload/attach file" screen. When done, the user returns to the [compose email] screen and can either attach another file or submit the e-mail.
How can I solve this problem? Should I use a form within a form?

How do I keep track of the "e-mail" data, when going of to "attach file" and back?

Posted: Mon Nov 04, 2002 4:18 pm
by amnuts
You could serialize the $_POST information into a hidden form field. Then when you need it again just unserialize it into another array. You'll probably need to htmlentities it as well, such as:

<input type="hidden" name="data" value="<?php echo htmlentities(serialize($_POST)); ?>">

You could go one more step than that to make it a little harder to read in the view source, such as:

<input type="hidden" name="data" value="<?php echo htmlentities(base64_encode(gzcompress(serialize(($_POST))))); ?>">

Andy

hmmmm

Posted: Tue Nov 05, 2002 10:05 am
by terji
I'm a newbie

I do however see what you mean, but I would be greatful if you could take it down to "step by step" :oops:

Posted: Tue Nov 05, 2002 10:55 am
by amnuts
Okay, let's try to break this down.

Assuming you have 3 pages. Page 1 sends the initial form data to page 2. Page 2 sends the attachement data to page 3. Page 3 processes and send the email. What you want to do is retain the information from page 1 in page 2 and then use all of the data in page 3.

This is a VERY simplified example, but will give you something to go off:

page1.php

Code: Select all

<form action="page2.php" method="post">
<input type="text" name="user_name"><br>
<input type="text" name="send_to"><br>
<textarea name="message" rows="5" cols="40"><textarea><br>
<input type="submit" value="go to next stage">
</form>
page2.php

Code: Select all

<form action="page3.php" method="post" enctype="multipart/form">
<input type="hidden" name="previous_data" value="<?php echo base64_encode(gzcompress(serialize(($_POST)))); ?>"> 
<input type="file" name="attachement"><br>
<input type="submit" value="go to next stage">
</form>
page3.php

Code: Select all

<?php

$initial = unserialize(gzuncompress(base64_decode($_POST&#1111;'previous_data'])));
// do any and all processing and mail sending here

?>
So now on page3.php you have the variable '$initial' which is an array with anything that was in the original '$_POST' variable. So you can access the data such as:

Code: Select all

<?php

echo $initial&#1111;'user_name'], "<br>\n";
echo $initial&#1111;'send_to'], "<br>\n";
echo $initial&#1111;'message'], "<br>\n";

?>
Hope that helps.

Andy