View Issue Details

IDProjectCategoryView StatusLast Update
04586User patchesOtherpublic2010-12-14 13:02
Reporteruser9586Assigned Toc_schmitz 
PrioritynormalSeverityminor 
Status closedResolutionfixed 
Product Version1.90 
Target VersionFixed in Version1.91 
Summary04586: Allow to restrict numbers to integers.
Description

This patch adds a new option to "Number" question types named "Restrict to integer values". When enabled, you are forced to insert an integer number (the comma - or dot in some countries - is disabled) in the field.

This is used, for example, on questions that require an exact integer as an answer, like: "How many children do you have?" (we have seen people entering "1.5" to indicate pregnancy).

Additional Information

The check is also enforced server-side, on the checkpregs() function. I've seen that the number itself is not validated unless you use a RE, which is a pity. I was able to insert plain test by simply sending an ad-hoc POST.

checkpregs() seemed the best function to plug this check, since it is already called for all three questionnaire modes and when saving. I used this function to perform server-side validation of the new question types I will submit. I would have renamed this function into checkval(), but I didn't.

TagsNo tags attached.
Complete LimeSurvey version number (& build)9089

Activities

user9586

2010-09-10 16:17

  ~12825

Updated patch to fix some undefined warnings.

c_schmitz

c_schmitz

2010-10-11 23:55

administrator   ~13097

Can you please provide the patch as a subversion patch (svn diff) against our 1.91 development version at the subversion branch at :
https://limesurvey.svn.sourceforge.net/svnroot/limesurvey/source/limesurvey_dev

Thank you!

user9586

2010-10-18 17:14

  ~13233

Updated the patch against latest SVN version.

c_schmitz

c_schmitz

2010-10-18 21:24

administrator   ~13235

Dear Wavex,

you used

https://limesurvey.svn.sourceforge.net/svnroot/limesurvey/source/limesurvey

as the base for your patch
but the development version is in

https://limesurvey.svn.sourceforge.net/svnroot/limesurvey/source/limesurvey_dev

Can you please have another look at it?

Thank you!

user9586

2010-10-19 19:52

  ~13255

I'm having a hard time just testing limesurvey_dev.

duplicated function display_first_page() (in both index.php and question.php).

and:

Fatal error: Call to undefined function usedTokens() in limesurvey/index.php on line 2430

c_schmitz

c_schmitz

2010-10-19 20:07

administrator   ~13256

Hi wavexx,

thank you for letting us know. Both issue should be fixed now.

user9586

2010-10-19 20:12

  ~13257

Got a bit further, but not much:

Fatal error: Call to a member function RecordCount() on a non-object in limesurvey/index.php on line 672

c_schmitz

c_schmitz

2010-10-19 20:14

administrator   ~13258

I cannot reproduce. When do you get this - can you attach that survey?

c_schmitz

c_schmitz

2010-10-19 20:34

administrator   ~13259

Nevermind - Found and fixed.

user9586

2010-10-19 22:47

  ~13283

Warning: Invalid argument supplied for foreach() in limesurvey/save.php on line 123 Notice: Undefined index: savetimings in /home/ydelia/public_html/limesurvey/save.php on line 189

user9586

2010-10-19 22:48

 

patch-svn-dev.diff (2,883 bytes)
Index: common_functions.php
===================================================================
--- common_functions.php	(revision 9285)
+++ common_functions.php	(working copy)
@@ -3610,6 +3610,18 @@
     "help"=>$clang->gT('SGQA identifier to use total of previous question as total for this question'),
     "caption"=>$clang->gT('Value equals SGQA'));
 
+    $qattributes["num_value_int_only"]=array(
+    "types"=>"N",
+    'category'=>$clang->gT('Input'),
+    'sortorder'=>100,
+    'inputtype'=>'singleselect',
+    'options'=>array(
+        0=>$clang->gT('No'),
+        1=>$clang->gT('Yes')),
+    'default'=>0,
+    "help"=>$clang->gT('Restrict to integer values'),
+    "caption"=>$clang->gT('Integer only'));
+
     $qattributes["numbers_only"]=array(
         "types"=>"Q;S",
         'category'=>$clang->gT('Other'),
Index: qanda.php
===================================================================
--- qanda.php	(revision 9285)
+++ qanda.php	(working copy)
@@ -4622,9 +4622,19 @@
     {
         $tiwidth=10;
     }
+
+    if (trim($qidattributes['num_value_int_only'])==1)
+    {
+        $acomma="";
+    }
+    else
+    {
+        $acomma=".,";
+    }
+
     // --> START NEW FEATURE - SAVE
     $answer = "<p class=\"question\">\n\t$prefix\n\t<input class=\"text\" type=\"text\" size=\"$tiwidth\" name=\"$ia[1]\" "
-    . "id=\"answer{$ia[1]}\" value=\"{$_SESSION[$ia[1]]}\" alt=\"".$clang->gT('Answer')."\" onkeypress=\"return goodchars(event,'-0123456789.')\" onchange='$checkconditionFunction(this.value, this.name, this.type)'"
+    . "id=\"answer{$ia[1]}\" value=\"{$_SESSION[$ia[1]]}\" alt=\"".$clang->gT('Answer')."\" onkeypress=\"return goodchars(event,'-0123456789$acomma')\" onchange='$checkconditionFunction(this.value, this.name, this.type)'"
     . "maxlength=\"$maxsize\" />\n\t$suffix\n</p>\n";
     if ($qidattributes['hide_tip']==0)
     {
Index: index.php
===================================================================
--- index.php	(revision 9285)
+++ index.php	(working copy)
@@ -1822,8 +1822,22 @@
                         if (!@preg_match($preg, $_POST[$field]))
                         {
                             $notvalidated[]=$field;
+                            continue;
                         }
                     }
+
+                    // check for other question attributes
+                    $qidattributes=getQuestionAttributes($fieldinfo['qid'],$fieldinfo['type']);
+
+                    if ($fieldinfo['type'] == 'N')
+                    {
+                        if (trim($qidattributes['num_value_int_only'])==1 &&
+                            !preg_match("/^[0-9]+$/", $_POST[$field]))
+                        {
+                            $notvalidated[]=$field;
+                            continue;
+                        }
+                    }
                 }
             }
         }
patch-svn-dev.diff (2,883 bytes)

user9586

2010-10-19 22:48

  ~13284

Patch updated (but please note the warning above I get in the current SVN head).

user9586

2010-10-21 11:07

  ~13297

I also get the following at the first question of the survey:

Notice: Undefined variable: grouptoken in limesurvey/question.php on line 625

user9586

2010-11-04 11:31

  ~13414

Is there any way I could help to speed up the process?
The time I'm allowed to work full-time on this project is running out.

c_schmitz

c_schmitz

2010-11-04 13:13

administrator   ~13417

Hello Wavexx,

I successfully applied the patch now and it looks good.
It was confusing because you wrote in another issue what build number the patch in this issue is based on.

To speed up the process please let me know which is the next patch that should be applied and what build number it is based on, either here or in the next patch.
I will then be speedy in application and feedback.
Thank you!

Issue History

Date Modified Username Field Change
2010-09-09 11:17 user9586 New Issue
2010-09-09 11:17 user9586 File Added: patch.diff
2010-09-10 16:17 user9586 Note Added: 12825
2010-09-10 16:17 user9586 File Added: patch2.diff
2010-10-11 23:55 c_schmitz Status new => feedback
2010-10-11 23:55 c_schmitz Note Added: 13097
2010-10-18 17:13 user9586 File Added: patch-svn.diff
2010-10-18 17:14 user9586 Note Added: 13233
2010-10-18 17:14 user9586 Status feedback => new
2010-10-18 21:21 c_schmitz File Deleted: patch.diff
2010-10-18 21:21 c_schmitz Assigned To => c_schmitz
2010-10-18 21:21 c_schmitz Status new => assigned
2010-10-18 21:21 c_schmitz File Deleted: patch2.diff
2010-10-18 21:24 c_schmitz Note Added: 13235
2010-10-18 21:24 c_schmitz Status assigned => feedback
2010-10-19 19:52 user9586 Note Added: 13255
2010-10-19 19:52 user9586 Status feedback => assigned
2010-10-19 20:07 c_schmitz Note Added: 13256
2010-10-19 20:07 c_schmitz Status assigned => feedback
2010-10-19 20:12 user9586 Note Added: 13257
2010-10-19 20:12 user9586 Status feedback => assigned
2010-10-19 20:14 c_schmitz Note Added: 13258
2010-10-19 20:34 c_schmitz Note Added: 13259
2010-10-19 20:34 c_schmitz Status assigned => feedback
2010-10-19 22:47 user9586 Note Added: 13283
2010-10-19 22:47 user9586 Status feedback => assigned
2010-10-19 22:48 user9586 File Added: patch-svn-dev.diff
2010-10-19 22:48 user9586 Note Added: 13284
2010-10-21 00:46 c_schmitz File Deleted: patch-svn.diff
2010-10-21 11:07 user9586 Note Added: 13297
2010-11-04 11:31 user9586 Note Added: 13414
2010-11-04 13:13 c_schmitz Note Added: 13417
2010-11-04 13:13 c_schmitz Status assigned => resolved
2010-11-04 13:13 c_schmitz Fixed in Version => 1.91
2010-11-04 13:13 c_schmitz Resolution open => fixed
2010-12-14 13:02 c_schmitz Status resolved => closed