Creating a custom spiritual gifts assessment questionnaire

Okay, we’re back for another fun and exciting week of CCB tutorials.

Today, we’re picking up where we last left off: spiritual gifts assessment software.

Using my prophetic gifting, I sense you’re about to bolt me, so don’t bolt on me just yet. 😉

We’re not going to discuss how to qualify a spiritual gifting assessment, but I will teach you how to create a simple spiritual gifts assessment questionnaire form using an excel spreadsheet.

Of course, you could use a database (highly recommended), but I’d rather not get too complicated for those of us that are technically challenged.

Oh before I forget, I’m ONLY cover the following today:

  • Creating a php form
  • Creating excel spreadsheet of spiritual gift questions and CCB spiritual gifts key
  • Parse excel spreadsheet to display questions

We WON’T cover submitting, validating, storing and keying responses for each individual questionnaire submitted by users.

We’ll cover aforementioned topics in detail in the coming week or so. Okay, let’s get rolling with today’s tutorial.

Setting Up Your PHP Form

Let’s start with the easy step first which is creating a simple HTML5 form.

This form won’t be as glamorous as a CCB, Typeform or Wufoo form, but it’ll get the job done for this tutorial.

In the coming weeks, I’ll show you how to use Typeform and Wufoo for a more elegant user experience.

Nevertheless, I’ve provided the necessary form details, instructions/guide and code below for you to copy and tweak as you desire.

    <!DOCTYPE html>
    <html lang="en-US">

    <head>
        <meta charset="UTF-8">
        <title>Spiritual Gifts Assessment</title>
    </head>

    <body>
        <form method="post" action="<?php echo $_SERVER[" PHP_SELF "];?>">
                    <h1>Spiritual Gifts Assessment</h1>
                    <p>
                        <label>First Name</label>
                        <input name="firstname" placeholder="Type Here" required />
                    </p>
                    <p>
                        <label>Last Name</label>
                        <input name="lastname" placeholder="Type Here" required />
                    </p>
                    <p>
                        <label>Email</label>
                        <input name="email" type="email" placeholder="Type Here" required />
                    </p>
                    <h2>DIRECTIONS</h2>
                    <p>This is not a test, so there are no wrong answers. The Spiritual Gifts Survey consists of 80 statements. Some items reflect concrete actions; other items are descriptive traits; and still others are statements of belief.</p>
                    <ul>
                        <li>Select the one response you feel best characterizes yourself and place that number in the blank provided. Record your answer in the blank beside each item.</li>
                        <li>Do not spend too much time on any one item. Remember, it is not a test. Usually your immediate response is best.</li>
                        <li>Please give an answer for each item. Do not skip any items.</li>
                        <li>Do not ask others how they are answering or how they think you should answer.</li>
                        <li>Work at your own pace.</li>
                    </ul>
                    Your response choices are:
                    <ul>
                        <li>5 — Highly characteristic of me/definitely true for me</li>
                        <li>4 — Most of the time this would describe me/be true for me</li>
                        <li>3 — Frequently characteristic of me/true for me – about 50 percent of the time</li>
                        <li>2 — Occasionally characteristic of me/true for me - about 25 percent of the time</li>
                        <li>1 — Not at all characteristic of me/definitely untrue for me</li>
                    </ul>
                        <input id="submit" name="submit" type="submit" value="Submit">
        </form>
    </body>

    </html>

Creating the question and key excel spreadsheet

Yeah, yeah… I know that most techies wouldn’t consider using an excel spreadsheet the most efficient manner to create a questionnaire and key.

Again, I don’t recommend it for long term use as a database provides more flexibility and scale than does an excel spreadsheet.

But for the sake of this tutorial and making it more friendly for our non-tech users, excel spreadsheet it is. 🙂

Open excel spreadsheet, save it as question-key.csv, and create two columns: Question and Category.

Type one question per row in the question column, and using CCB’s Spiritual Gifts list, type in a category for each question. Read this tutorial to retrieve a list of CCB Spiritual gifts.

This binding of question and category will be used in the coming weeks to group and display how a person scored on the assessment.

Download Example Question-Key.csv File

Parsing excel spreadsheet to display form questions

Okay, were not ready to parse, add and display form questions using a bit of PHP magic.

At the very top of your form, add in the following line of PHP code:

<?PHP

$formFieldData = prepareQuestions();

?>

To make things simple and easy to find, we’ll make use of functions. I’ll cover the functions prepareQuestions and outputQuestions at the very end of this tutorial.

Now that you have defined the formFieldData variable and set it equal to prepareQuestions, you’re ready to place the following line of code just about the form submit button as shown below:

<? echo $formFieldData; ?>
                        <input id="submit" name="submit" type="submit" value="Submit">
        </form>
    </body>

    </html>

And that’s it! You’ve now respectively parsed, captured and displayed each form question and input.

Time to test your PHP parsing prowess

By now, you’re code should look like the code shown below.

Save your php form and the question-key.csv in the same directory, and load the php form via a web browser to be wowed by your PHP prowess.

<?PHP

$formFieldData = prepareQuestions();

?>
    <!DOCTYPE html>
    <html lang="en-US">

    <head>
        <meta charset="UTF-8">
        <title>Spiritual Gifts Assessment</title>
    </head>

    <body>
        <form method="post" action="<?php echo $_SERVER[" PHP_SELF "];?>">
                    <h1>Spiritual Gifts Assessment</h1>
                    <p>
                        <label>First Name</label>
                        <input name="firstname" placeholder="Type Here" required />
                    </p>
                    <p>
                        <label>Last Name</label>
                        <input name="lastname" placeholder="Type Here" required />
                    </p>
                    <p>
                        <label>Email</label>
                        <input name="email" type="email" placeholder="Type Here" required />
                    </p>
                    <h2>DIRECTIONS</h2>
                    <p>This is not a test, so there are no wrong answers. The Spiritual Gifts Survey consists of 80 statements. Some items reflect concrete actions; other items are descriptive traits; and still others are statements of belief.</p>
                    <ul>
                        <li>Select the one response you feel best characterizes yourself and place that number in the blank provided. Record your answer in the blank beside each item.</li>
                        <li>Do not spend too much time on any one item. Remember, it is not a test. Usually your immediate response is best.</li>
                        <li>Please give an answer for each item. Do not skip any items.</li>
                        <li>Do not ask others how they are answering or how they think you should answer.</li>
                        <li>Work at your own pace.</li>
                    </ul>
                    Your response choices are:
                    <ul>
                        <li>5 — Highly characteristic of me/definitely true for me</li>
                        <li>4 — Most of the time this would describe me/be true for me</li>
                        <li>3 — Frequently characteristic of me/true for me – about 50 percent of the time</li>
                        <li>2 — Occasionally characteristic of me/true for me - about 25 percent of the time</li>
                        <li>1 — Not at all characteristic of me/definitely untrue for me</li>
                    </ul>
                    <? echo $formFieldData; ?>
                        <input id="submit" name="submit" type="submit" value="Submit">
        </form>
    </body>

    </html>
    <?PHP

function prepareQuestions(){

$randNum = false;
$err_upTmpName = 'question-key.csv';
$row = 0;
$formFields = '';

if (($handle = fopen($err_upTmpName, "r")) !== FALSE) {

	while (($data = fgetcsv($handle, 0, ",")) !== FALSE) {

		if($row == 0){ 

			$row++; 

		} else {

			// $data[0] = question;
			/**********************/
			if(!empty($data[0]))
				$formFields .= outputQuestion($row,$data[0]);

			$row++;

		}
	}

} else {

	$formFields .= 'File could not be opened.';
}	

fclose($handle);

return $formFields;

}

function outputQuestion($rowNumber,$questionData){

	$formFields = '';
	$formFields .= '<p style="padding: 4px 2px;">';
	$formFields .= '<input name="ans[]" style="padding: 4px 2px; margin: 0px 4px; width: 25px;" min="1" max="5" type="number" maxlength="1"';
	$formFields .= ' required /> ';
	$formFields .= $rowNumber.') '.$questionData.'</p>';

	return $formFields;

}

?>

Although we’ve tailored this particular tutorial to focus on spiritual gifts assessment, you could easily change the questions and response choice text to account for a variety of opinion or scaled-based question and answer surveys.

Again, I recommend using a database, but this is a simple and fast method to create a reusable form using an excel spreadsheet to host your questions and key.

That’s it for today! Next week, we’ll cover the following in great detail:

  • Submitting and validating form data
  • Excluding certain questions based on key category
  • Summing, grouping and storing the results via an excel spreadsheet

If you have questions, please don’t hesitate to drop me a comment below. See you next week.

prepareQuestions Function

The prepareQuestions function simply reads the question-key.csv file to retrieve the question and question number data to pass along to the outputQuestion function for html placement.

Read this tutorial to learn and receive the inside scoop on how to parse an excel/csv file using php.

<?PHP

function prepareQuestions(){

$randNum = false;
$err_upTmpName = 'question-key.csv';
$row = 0;
$formFields = '';

if (($handle = fopen($err_upTmpName, "r")) !== FALSE) {

	while (($data = fgetcsv($handle, 0, ",")) !== FALSE) {

		if($row == 0){ 

			$row++; 

		} else {

			// $data[0] = question;
			/**********************/
			if(!empty($data[0]))
				$formFields .= outputQuestion($row,$data[0]);

			$row++;

		}
	}

} else {

	$formFields .= 'File could not be opened.';
}	

fclose($handle);

return $formFields;

}

?>

outputQuestion Function

The outputQuestion function simply prepares the html and form elements using the data output of the question and question number data from the prepareQuestions function.

<?PHP

function outputQuestion($rowNumber,$questionData){

	$formFields = '';
	$formFields .= '<p style="padding: 4px 2px;">';
	$formFields .= '<input name="ans[]" style="padding: 4px 2px; margin: 0px 4px; width: 25px;" min="1" max="5" type="number" maxlength="1"';
	$formFields .= ' required /> ';
	$formFields .= $rowNumber.') '.$questionData.'</p>';

	return $formFields;

}

?>

Related Posts

Subscribe and receive the following...

  • Inside CCB tips and tricks
  • Instant CCB tutorial alerts and updates
  • CCB How To's, Videos, Webinars and more...