vendredi 17 avril 2015

Populate a certificate with information from a form on another page in php

I am creating e-learning that users will take a quiz. Upon submit they will be sent to the results page where it will show them their scores. If the user passes a link will pop up to a certificate they can print out. I cannot get the certificate to populate variables(first name, last name, etc). Here is what I have:


index.php (home page where they take the quiz and fill out a form)



<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" />&nbsp;
</label>
<label>First Name:
<input type="text" name="fname" id="fname" tabindex="2" />&nbsp;
</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>


On results.php (page that shows results and link to certificate)



<?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>


On 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>


Thank you!


Aucun commentaire:

Enregistrer un commentaire