Jump to content

multipage form/survey


thefortrees

Recommended Posts

Hi all,

 

I am developing an online survey tool for a client and wanted community input or any ideas anybody may want to offer. My problem is this: any user of the system can log in and create a custom survey. This user then creates survey codes to give to others. The 'customers' (people who hold survey codes) log in to take a survey using those codes.  The survey needs to be broken up into multiple pages (ie - if there are 25 questions, 5 questions per page, so total of 5 pages). However, if the user does not finish the form and submit it at the last page, then the data should not be stored.

 

I am trying to implement the most efficient and effective design for this application.

 

Currently, I am thinking of using a 'temporary_results' table which would store the interim results before the entire survey is completed. If a user completes the survey, then survey data is stored in a 'final_results' table. Also, every survey page will pass the next question numbers to retrieve from the database to the next form. Any input on this?

 

If anybody has developed an application similar to this before, suggestions or comments would be greatly appreciated!

 

 

Link to comment
https://forums.phpfreaks.com/topic/100379-multipage-formsurvey/
Share on other sites

Here's one I did recently. Looks like five forms but is only one.

 

<?php
$cfg = parse_ini_file('pmp_q.ini', 1);
$sections = array_keys($cfg);

//echo '<pre>', print_r($cfg, true), '</pre>';  
//echo '<pre>', print_r($sections, true), '</pre>';

function makeSection($sno)
{
    global $cfg, $sections;
    
    $q = $v = array();
    $ks = count($sections);
    
    $preSect = $sno==0? '' : $sections[$sno-1];
    $nexSect = $sno==$ks-1 ? '' : $sections[$sno+1];
    $prelink = "javascript:showHideSection(\"$preSect\")";
    $nexlink = "javascript:showHideSection(\"$nexSect\")";
    $nextText = $sno==$ks-1 ? "<input type='submit' name='sub' value='Finish'>" : "<a href='$nexlink'>next »</a>";
    $prevText = $sno==0 ? '' : "<a href='$prelink'>« back</a>";
    
    $s = $sections[$sno];
    $tmp = $cfg[$s];
    foreach ($tmp as $txt)
    {
        list($q[], $v[]) = explode('||', $txt);
    }
    echo " 
        <div class='section' id='$s'>
              <div class='stitle'>
                    $s
                    <span class='small'><br/><br/>SELECT ONE</span>
              </div>
              
                  <table>\n";
                    foreach($q as $k=>$qtext)
                    {
                        $val = $v[$k];
                        $chk = $k==0 ? 'checked=checked' : '';
                        printf("<tr valign='top'><td width='12%%'>%d.</td>
                        <td width='73%%'>%s<br><br></td>
                        <td width='15%%'><input type='radio' name='%s' value='%d' $chk>
                        <span class='small'>Yes</span>
                        </td></tr>\n",
                            $k+1, $qtext,$s,$val);
                    }          
                    echo "</table>
             
            <div class='nav'>
                 <div style='float: left'> $prevText </div>
                 <div style='float: right'> $nextText </div> 
            </div>
        </div>\n";
      
}

?>
<html>
<head>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta name="generator" content="PhpED Version 4.5 (Build 4513)">
<title>PMP Pathfinder</title>
<meta name="author" content="Barand">
<meta name="creation-date" content="03/13/2008">
<script language="javascript">

         var currentSection=null;
         
         function showHideSection(sid)
         {
             if (currentSection != null)
             {
                currentSection.style.visibility = "hidden";
             }
             var newsec = document.getElementById(sid);
             newsec.style.visibility = "visible";
             currentSection = newsec;
         }
</script>
<style type="text/css">
body {
    margin: 0;
}

div {
    font-family: Arial;
}

div.nav {
    margin : 10px 20px;
}

div.section {
    width: 60%;
    border: 2pt solid #AC876F;
    position: absolute;
    top: 110px;
    left: 100px;
    visibility: hidden;                      
/*    margin-top: 50px;
    margin-left: 100px; */
}

div.stitle {
    background-color: #e3dbd9;
    color: #FFF;
    height: 60px; 
    font-size: 1.5em;
    font-weight: 600;
    font-style: italic;
    text-align: right;
    padding: 14px;    
}

#title {
    background-color: #B04;
    color: #FFF;
    height: 40px;
    font-size: 2.5em;
    font-weight: 600;
    padding: 10px;
}

table {
    margin: 20px;
    
}
td {
    color: #AC876F;
    font-size: 1.2em;
    font-weight: 500;
}
span.small {
    font-size: 7pt;
    margin-right: 18px;
}

a {
    font-size: 9pt;
    color: #AC876F;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}
</style>
</head>
<body onload='showHideSection("Funding")'>
<div id='title'>
PMP pathfinder  <span style='font-size: 0.5em'> - answer five simple questions</span>
</div>


<?php 
        echo "<form method='POST' action='pmp_rf2.php'>\n";
        for ($i=0, $k=count($sections); $i<$k; $i++)
        {
            makeSection($i);
        }  
        echo "</form>\n";

?>


</body>
</html>

 

and the config data

[Funding]
1="Is the work funded from your department budget?||5"
2="Is the funding from a mixture of department budgets but still within the company?||10"
3="Will any of the funding come from external sources?||15"

[benefits]
1="Will only your department benefit from the work?||1"
2="Will the whole of the company benefit from the work?||2"
3="Will there be a direct benefit to customers?||3"

[Consultation]
1="Do you need to consult only your department?||4"
2="Do you need to consult only within the company?||8"
3="Do you need to inform/consult with external parties?||12"

[Duration]
1="Will the work be completed in less than three months?||3"
2="Will the work take longer than three months but less than twelve months to complete?||6"
3="Will the work take longer than twelve months?||9"

[Resources]
1="Will the work be undertaken only by staff in your department?||2"
2="Will the work be undertaken only by staff in the company but not just in your department?||4"
3="Will you need external resources to undertake some or all of the work?||6"

Link to comment
https://forums.phpfreaks.com/topic/100379-multipage-formsurvey/#findComment-513347
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.