【发布时间】:2011-10-11 18:58:13
【问题描述】:
我无法弄清楚这一点,并尝试了几种方法。
我有一个多页表单,form_1.php 在提交时将信息发送到数据库并重定向到 form_2.php。
我在 form_1.php 上开始一个会话:
<?PHP
if ($_POST)
{
session_start();
foreach ($_POST as $field => $value)
{
$_SESSION['formdata'][$field] = $value;
}
}
.....code that sends info to db and then redirects page to form_2.php
?>
当我到达 form_2.php 时,我有:
<?php
session_start();
if (!empty($_POST)) {
// Used for later to determine result
$success = $error = false;
// Object syntax looks better and is easier to use than arrays to me
$post = new stdClass;
// Usually there would be much more validation and filtering, but this
// will work for now.
foreach ($_POST as $key => $val)
$post->$key = trim(strip_tags($_POST[$key]));
....more code that loads dompdf and sends a pdf to email
?>
如果我使用类似的东西:
<?php echo $post->Name; ?>
<?php echo $post->Address; ?>
<?php echo $post->City; ?>
<?php echo $post->State; ?>
我希望在哪里显示数据,但我什么也得不到。
有没有办法写这个相当于:
<?php echo $_SESSION['Name'] ?>
是因为我在使用对象吗?
如果我擦除 form_2.php 中的所有内容并使用以下命令打印会话:
<?php
session_start();
Print_r ($_SESSION);
?>
我看到了我想要的数据:
Array ( [sfm_from_iframe] => 0 [formdata] => Array ( [sfm_form_submitted] => yes [Employer_Zip] => 33333 [Injury_type] => Array ( [0] => Head [1] => Left Shoulder [2] => Chest ) [FirstName] => test [LastName] => tester [Address] => 1212 myaddy [City] => city1 [State] => Maine [Zip] => 55555 [Country] => AntiguaAndBarbuda [Phone] => 555-555-5555 [Email] => me@mydomain.com [Employer_Name] => my employer [Employer_Address] => 1212 empaddy [Employer_City] => city2 [Employer_State] => Georgia [DBA_Carrier] => mycarrier [Employer_Phone] => 333-333-3333 [Accident_Date] => 10-03-2011 [Message] => asefsafsadf sadf asdfsdafsadf [yes_no] => yes [SocialSecurity] => 333-33-3333 [Submit_x] => 57 [Submit_y] => 13 ) )
可能有帮助的附加说明...
当我只是使用 POST 到 form_2.php 并使用
<?php echo $post->Name; ?>
<?php echo $post->Address; ?>
<?php echo $post->City; ?>
一切都显示出来并且工作正常,但只能直接使用 POST 到该页面。不使用重定向,因为我认为我在编写如何回显 SESSION 对象时搞砸了。
有什么想法吗?
【问题讨论】:
-
我不太明白您的会话问题是什么。能否获取form_2.php的源代码?