Jump to content

PHP multiform processing


shawnm

Recommended Posts

I've tried two different approaches (below) to solve the problem of taking data entered in multiple forms on muliple pages and having it sent to me in a single email.

 

approach 1:

 

<?php

 

while (list($name, $value) = each($HTTP_POST_VARS))

  {

  echo "<input type=\"hidden\" value=\"$value\" name=\"$name\">\n";

  }

 

?>

 

Approach 2:

 

session_start();

 

if(!$_SESSION['ses_request']){$_SESSION['ses_request'] = $_REQUEST;}else{$_SESSION['ses_request'] = array_merge($_SESSION['ses_request'],$_REQUEST);}

 

I entered code where I've read i'm supposed to but it doesn't work. The only info that is forwarded to my email is that which i enter in the last form on the last page before clicking the 'submit' button and posting the info. The data from the other forms won't carry over. Any advice or suggestions?

 

Thanks.

Shawn

Link to comment
https://forums.phpfreaks.com/topic/122816-php-multiform-processing/
Share on other sites

First off that $HTTP_POST_VARS is old method use $_POST or $_GET

Secondly

you can try this

on form 2 (form 1 processes here) 
[code]
<?php
session_start();
foreach($_POST as $key=>$value){
$_SESSION['Form1'][$key] = $value;
}
?>

 

Form 3 (form 2 processes here)

<?php
session_start();
foreach($_POST as $key=>$value){
$_SESSION['Form2'][$key] = $value;
}
?>

etc.

 

then just put all thoses session arrays in such as

 

<?php
session_start();
$i = 1;
$message = "Blah\r\n\r\n";
while($i <= $num_forms){
foreach($_SESSION['Form'.$i] as $key=>$value){
$message .= $key.": ".$value."\r\n";
}
$i++;
}
?>

[/code]

You need to use a double comparison operator on the while statement.

 

<?php

while (list($name, $value) == each($HTTP_POST_VARS))
 {
  echo "<input type=\"hidden\" value=\"$value\" name=\"$name\">\n";
 }

?>

Approach 2:

 

On another note, you should post your code on code tags.

You need to use a double comparison operator on the while statement.

 

Its not a comparison its an initialization of those variables

 

if the list function fails to "list" the variables then it says while()  which should fail

 

List doesn't return a FALSE if it fails to list anything so be observant of that

 

the same concept is commonly used doing

<?php
while($row = mysql_fetch_assoc($r)){
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.