我正在创建电子学习,以便用户进行测验。提交后,他们将被发送到结果页面,其中将显示他们的分数。如果用户通过,链接将弹出一个证书,他们可以将其打印出来。我无法获得用于填充变量(名字,姓氏等)的证书。这是我所拥有的:
index.php(他们进行测验并填写表格的主页)
<form id="form1" name="form1" method="post" action="results.php" onsubmit="return validateForm() ;">
<label>Last Name:
<input type="text" name="lname" id="lname" tabindex="1" />
</label>
<label>First Name:
<input type="text" name="fname" id="fname" tabindex="2" />
</label>
<label>Title:
<input type="text" name="title" id="title" tabindex="3" /><br/><br/>
</label>
<?php
$quiz = new Quiz( $questions );
echo $quiz->renderQuiz();
?>
<input name="Submit" type="submit" value="Submit" />
</form>
在results.php(显示结果和证书链接的页面)上
<?php
$ip = $_SERVER['REMOTE_ADDR']; // employee's Ip address
$time = date("d/m/y : H:i:s", time()); // current timestamp
$email_string = create_email_string( $force_email, $_POST['email_to'] );
$questions_correct = array();
$info_to_save = array( $_POST['lname'], $_POST['fname'], $_POST['title'];
// Grades the quiz
$score = (string)round( ( count($questions_correct) / count($questions)*100), 2 );
$variables = array();
$variables['fname'] = $_POST['fname'];
$variables['lname'] = $_POST['lname'];
$variables['test_name'] = $test_name;
$variables['score'] = $score;
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test Results</title>
<link rel="stylesheet" type="text/css" href="./stylesheets/quiz_stylesheet.css" />
</head>
<body>
<div id="white">
<div id="header">
<img src="./images/ucdheader.jpg" width="1000" id="header" /img>
</div>
<div id="mainContent">
<h1><span>You Scored <?php echo $score ?>%</span>
<br><?php if ($score >= 80)
echo "<a href=certificate.php >Print Certificate</a>
"?></h1>
<p>Below are your results for <?php echo $test_name; ?>. In order to pass this quiz, you must score 80% or better. If you would like to try again, click the following link.</p>
<a href='<?php echo $test_page_name ?>'>Try again</a>
<p>These results were sent to the following addresses: </p>
<ul>
<?php
$all_emailed_to = explode( "; " , $email_string);
foreach ($all_emailed_to as $email) {
echo "<li>" . $email . "</li>";
}
?>
</ul>
</div>
</div>
</body>
</html>
在certificate.php上
<title>Certificate</title>
</head>
<body>
<div id="white">
<div class="btn-group btn-group-lg">
<a role="button" class="btn btn-default" href="#" data- function="print">Print Certificate</a>
</div>
<div class="certificate">
<img src="images/cert.png" width="820" height="527" id="cert" />
<div class="name">
<?php $variables['fname'] . " " . $variables['lname'] . ?>
</div>
<div class="course">
<p></p>
</div>
<div class="completion_date">
<?php $variables['time']; ?>
</div>
</div>
</div>
</body>
</html>
谢谢!
您没有将任何变量传递给certificate.php页面。在php页面之间传递数据有几种选择,例如:1)会话2)$ _POST 3)$ _GET
在最简单的代码中的方法是使用$ _GET变量。只需在results.php中使用以下代码行:
echo "<a href=certificate.php?fname={$variables['fname']}&lname={$variables['lname']} >Print Certificate</a>"?></h1>
比certificate.php中使用以下方法检索数据:<?php echo $_GET['fname'] . " " . $_GET['lname'] . ?>
注意1:您需要urlendode()
链接中的变量,以防有人在其名字/姓氏中放上特殊的椅子。注意2:这是一种可入侵的方法。员工可以通过调用准备好的URL打印带有任何名称/姓氏的证书。
最好的方法是重写所有三个页面以使用Sessions:http : //php.net/manual/en/features.sessions.php
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句