-3
<?php
class JpResearchSurveyDbPage extends DataObject{
static $db = array(
'year_living' => 'Varchar(200)',
'other_public_transport' => 'Varchar(50)',
'year_living1' => 'Varchar(200)',
'type_of_mode_unfamiliar_services' => 'Varchar(50)'
);
enter code here
}
$host="localhost"; 
$username="sgevh_admin"; 
$password="q1w2e3r4t5";  
$db_name="sgevh_test";
$con = mysql_connect("$host","$username","$password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("$db_name", $con);

$sql="INSERT INTO year (aaa,bbb,ccc,eee)
VALUES
('$_POST[year_living]','$_POST[other_public_transport]','$_POST[type_of_mode_unfamiliar_services]','$_POST[year_living1]')";

    //$sql="INSERT INTO month (ccc)
    //VALUES
    //('$_POST[type_of_mode_unfamiliar_services]')";

if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con);
?>`

//这是我们用来将多步表单连接到数据库的测试 php 编码。

<?php
class JpResearchSurveyMultiForm extends MultiForm{
public static $start_step = 'JpResearchSurveyFirstStep';
public function finish($data, $form){
parent::finish($data, $form);
$firstStep = $this->getSavedStepByClass('JpResearchSurveyFirstStep');
$_JpResearchSurveyFirstPage = new JpResearchSurveyDbPage();
$firstStep->saveInto($_JpResearchSurveyFirstPage);

$secondStep = $this->getSavedStepByClass('JpResearchSurveySecondStep');
$secondStep->saveInto($_JpResearchSurveyFirstPage);

$_JpResearchSurveyFirstPage->write();
return $this->controller->customise(array(
'Form' => false,
'Content' => 'Thanks for registering!'
))->renderWith('Page');
}
}
?>

//这是测试代码,它指示当我们按下“提交”按钮提交数据时表单的最后一步将做什么。当我们试用表单并使用我们的双页表单提交详细信息时,只有作为表单最后一步的第二页的字段数据存储在数据库中。

这两种编码中的哪一种给我们带来了无法在以前的表单会话中存储字段数据的问题?

4

1 回答 1

0

最好将每个步骤保存在数据库中并更新每个步骤。而是使用会话和 cookie 来管理用户输入,并在最后一步将它们存储在数据库中。请记住在之后终止会话

于 2012-11-28T08:44:42.337 回答