我無法弄清楚,並嘗試了幾種方法。如何在使用對象時回顯php會話
我有一個多頁的表單,其中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] => [email protected] [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的源代碼嗎? –