From: Brian W. <br...@uc...> - 2003-11-25 18:52:50
|
At 05:02 PM 11/25/2003 +0100, Johan Geertsma wrote: >Hi, > >Can someone tell me how to remove the results from 1 respondent? > >I now did it to set the COMPLETE to N. But I want to remove all the stuff >that this person submitted. I know how to find out which id he.she has. > > >Why? >Well that is my next question. How can I disable the enter key? >When people start a survey and hit enter, the form is submitted. >(yeah I could use the option that all answers are required). But you >guess it, the survey is not jet complete. > >I searched around for something to disable the enter key, but I see that >there is >a little javascript that does something before sending. Yeah I needed to disable that too since I am limiting responses to one. It's easy for a user to hit Enter and lock themselves out of a partially completed survey. I was trying to generate a nice diff for you, but I must have changed some formatting in this file. Below is handler.php which I'm pretty sure is the only file I needed to modify. Someone else may have more elegant way of doing this, but this has been working well for me: Line 83: if(!empty($HTTP_POST_VARS['submit']) || (isset($HTTP_POST_VARS['alt_submit']) && $HTTP_POST_VARS['alt_submit'] == 'Submit Survey')) { Line 194: <!-- prevent form from being submitted by enter key. --> <!-- input type="submit" name="submit" value="Submit Survey" --> <input type="hidden" name="alt_submit" value="Submit Survey"> <input type="button" value="Submit Survey" onClick="this.form.submit()"> Complete file below. Brian Wood Programmer/Analyst UC Berkeley Human Resources <pre> <?php # $Id: handler.php,v 1.24.2.1 2003/04/23 00:05:22 jimmerman Exp $ // Written by James Flemer // For eGrad2000.com // <jf...@al...> /* When using the authentication for responses you need to include * part of the script *before* your template so that the * HTTP Auth headers can be sent when needed. * * See the handler-prefix.php file for details. */ if (!defined('ESP_BASE')) define('ESP_BASE', dirname(dirname(__FILE__)) .'/'); require_once(ESP_BASE . '/admin/phpESP.ini.php'); require_once($ESPCONFIG['include_path']."/funcs".$ESPCONFIG['extension']); require_once($ESPCONFIG['handler_prefix']); if(!defined('ESP-AUTH-OK')) { if (!empty($GLOBALS['errmsg'])) echo($GLOBALS['errmsg']); return; } esp_init_db(); if (empty($HTTP_POST_VARS['referer'])) $HTTP_POST_VARS['referer'] = ''; // show results instead of show survey // but do not allow getting results from URL or FORM if(isset($results) && $results) { // small security issue here, anyone could pick a QID to crossanalyze survey_results($sid,$precision,$totals,$qid,$cids); return; } // else draw the survey $sql = "SELECT status, name FROM survey WHERE id='${sid}'"; $result = mysql_query($sql); if ($result && mysql_num_rows($result) > 0) list ($status, $name) = mysql_fetch_row($result); else $status = 0; if($status & ( STATUS_DONE | STATUS_DELETED )) { echo(mkerror(_('Error processing survey: Survey is not active.'))); return; } if(!($status & STATUS_ACTIVE)) { if(!(isset($test) && $test && ($status & STATUS_TEST))) { echo(mkerror(_('Error processing survey: Survey is not active.'))); return; } } if ($HTTP_POST_VARS['referer'] == $ESPCONFIG['autopub_url']) $HTTP_POST_VARS['referer'] .= "?name=$name"; $num_sections = survey_num_sections($sid); /* bug url_auth sections print $num_sections . "<br>"; print "post <pre> "; print_r($HTTP_POST_VARS); print "</pre><br>"; */ $msg = ''; $action = 'http://' . $HTTP_SERVER_VARS['HTTP_HOST'] . $HTTP_SERVER_VARS['PHP_SELF']; if (auth_get_option('url_tokens')) { // remove unnecessary stuff from query string $qs = preg_replace("/userid=\S+&?|p=\S+&?|sid=\S+&?/", "", $HTTP_SERVER_VARS['QUERY_STRING']); if (strlen($qs)) $action .= "?" . $qs; } elseif (!empty($HTTP_SERVER_VARS['QUERY_STRING'])) { $action .= "?" . $HTTP_SERVER_VARS['QUERY_STRING']; } //print "<pre>";print_r($HTTP_POST_VARS);print "</pre>"; if(!empty($HTTP_POST_VARS['submit']) || (isset($HTTP_POST_VARS['alt_submit']) && $HTTP_POST_VARS['alt_submit'] == 'Submit Survey')) { $msg = response_check_required($sid,$HTTP_POST_VARS['sec']); if(empty($msg)) { if ($ESPCONFIG['auth_response'] && auth_get_option('resume')) { response_delete($sid, $HTTP_POST_VARS['rid'], $HTTP_POST_VARS['sec']); } $HTTP_POST_VARS['rid'] = response_insert($sid,$HTTP_POST_VARS['sec'],$HTTP_POST_VARS['rid']); response_commit($HTTP_POST_VARS['rid']); response_send_email($sid,$HTTP_POST_VARS['rid']); if (auth_get_option('anonymous')) response_anonymize($HTTP_POST_VARS['userid'], false); // NULLs respondent.email // goto_thankyou($sid,$HTTP_POST_VARS['referer'], auth_get_option('urltokens')); goto_thankyou($sid,$HTTP_POST_VARS['referer'], true); return; } } if(!empty($HTTP_POST_VARS['resume']) && $ESPCONFIG['auth_response'] && auth_get_option('resume')) { response_delete($sid, $HTTP_POST_VARS['rid'], $HTTP_POST_VARS['sec']); $HTTP_POST_VARS['rid'] = response_insert($sid,$HTTP_POST_VARS['sec'],$HTTP_POST_VARS['rid']); if (auth_get_option('anonymous')) response_anonymize($HTTP_POST_VARS['userid']); if (auth_get_option('url_tokens')) { if ($action == $ESPCONFIG['autopub_url']) { goto_saved("$action?name=$name&userid={$HTTP_POST_VARS['userid']}&p=$esppass&sid=$sid"); } else { goto_saved($action); //TEST } return; } else { if ($action == $ESPCONFIG['autopub_url']) { goto_saved("$action?name=$name"); } else { goto_saved($action); } return; } } if(!empty($HTTP_POST_VARS['next'])) { $msg = response_check_required($sid,$HTTP_POST_VARS['sec']); if(empty($msg)) { if ($ESPCONFIG['auth_response'] && auth_get_option('resume')) response_delete($sid, $HTTP_POST_VARS['rid'], $HTTP_POST_VARS['sec']); $HTTP_POST_VARS['rid'] = response_insert($sid,$HTTP_POST_VARS['sec'],$HTTP_POST_VARS['rid']); if (auth_get_option('anonymous')) response_anonymize($HTTP_POST_VARS['userid']); $HTTP_POST_VARS['sec']++; } } if (!empty($HTTP_POST_VARS['prev']) && $ESPCONFIG['auth_response'] && auth_get_option('navigate')) { if(empty($msg)) { if (auth_get_option('resume')) response_delete($sid, $HTTP_POST_VARS['rid'], $HTTP_POST_VARS['sec']); $HTTP_POST_VARS['rid'] = response_insert($sid,$HTTP_POST_VARS['sec'],$HTTP_POST_VARS['rid']); if (auth_get_option('anonymous')) response_anonymize($HTTP_POST_VARS['userid']); $HTTP_POST_VARS['sec']--; } } if ($ESPCONFIG['auth_response'] && auth_get_option('resume')) response_import_sec($sid, $HTTP_POST_VARS['rid'], $HTTP_POST_VARS['sec']); /* (auth_get_option('resume')) ? print "res=y" : print "res=n"; print "<p><pre>"; // print_r($GLOBALS); print "<p></pre>"; */ ?> <script language="JavaScript"> <!-- // Begin <?php // This should really go into <head> tag ?> function other_check(name) { other = name.split("_"); var f = document.phpesp_response; for (var i=0; i<=f.elements.length; i++) { if (f.elements[i].value == "other_"+other[1]) { f.elements[i].checked=true; break; } } } // End --> </script> <form method="post" name="phpesp_response" action="<?php echo($action); ?>"> <input type="hidden" name="referer" value="<?php echo htmlspecialchars($HTTP_POST_VARS['referer']); ?>"> <input type="hidden" name="userid" value="<?php echo($HTTP_POST_VARS['userid']); ?>"> <?php if (auth_get_option('url_tokens')) { print "<input type=\"hidden\" name=\"p\" value=\"$esppass\">"; } ?> <input type="hidden" name="sid" value="<?php echo($sid); ?>"> <input type="hidden" name="rid" value="<?php echo($HTTP_POST_VARS['rid']); ?>"> <input type="hidden" name="sec" value="<?php echo($HTTP_POST_VARS['sec']); ?>"> <?php survey_render($sid,$HTTP_POST_VARS['sec'],$msg); ?> <?php if ($ESPCONFIG['auth_response']) { if (auth_get_option('navigate') && $HTTP_POST_VARS['sec'] > 1) { ?> <input type="submit" name="prev" value="Previous Page"> <?php } if ( (auth_get_option('resume')) && (!auth_get_option('url_tokens'))) { ?> <input type="submit" name="resume" value="Save"> <?php } } if($HTTP_POST_VARS['sec'] == $num_sections) { ?> <!-- prevent form from being submitted by enter key. --> <!-- input type="submit" name="submit" value="Submit Survey" --> <input type="hidden" name="alt_submit" value="Submit Survey"> <input type="button" value="Submit Survey" onClick="this.form.submit()"> <?php } else { ?> <input type="submit" name="next" value="Next Page"> <?php } ?> </form> </pre> |