View Issue Details

IDProjectCategoryView StatusLast Update
04751User patchesOtherpublic2012-06-21 14:14
ReporterCrystalBlood Assigned Toc_schmitz  
PrioritynormalSeverityminor 
Status closedResolutionfixed 
Product Version1.90 
Target VersionFixed in Version2.00 
Summary04751: Adding attribute fields in the register form of a survey
Description

Arouse the need in the registration form of a survey, that the custom attributes could be filled up in the form (only appear names and e-mail), currently this can be achieved loggin in and add manually the "participant" with the custom attributes.

So, i found in the common.php and register.php (common_functions.php and register.php in the limesurvey_dev repository) some commented code that meets my needs, and realized that it code was taking the approach, as the "static way".

I write some code, and now works like a charm, regardless of the number of attributes that exist.

See .diff's attached.

Additional Information

About the implementation, in the commonfunctions.php i use the function GetTokenFieldsAndNames to get the custom attributes as hash map, and for each key (name of the field) its generate a html input tag concatenating the word "register" with the key.

In the register.php we calculate the extra number of custom attributes with the name of the field, and dinamically appends to the insert sql statement.

It's a fast solution, but we call two times the function GetTokenFieldsAndNames.

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

Activities

CrystalBlood

CrystalBlood

2010-11-19 19:04

reporter  

patch_crystalblood.patch (4,100 bytes)
Index: common_functions.php
===================================================================
--- common_functions.php	(revision 9507)
+++ common_functions.php	(working copy)
@@ -3160,26 +3160,22 @@
 
 
         $registerform .= "<tr><td align='right'><input type='hidden' name='lang' value='".$reglang."' /></td><td></td></tr>\n";
-        /*      if(isset($thissurvey['attribute1']) && $thissurvey['attribute1'])
-         {
-         $registerform .= "<tr><td align='right'>".$thissurvey['attribute1'].":</td>\n"
-         ."<td align='left'><input class='text' type='text' name='register_attribute1'";
-         if (isset($_POST['register_attribute1']))
-         {
-         $registerform .= " value='".htmlentities(returnglobal('register_attribute1'),ENT_QUOTES,'UTF-8')."'";
-         }
-         $registerform .= " /></td></tr>\n";
-         }
-         if(isset($thissurvey['attribute2']) && $thissurvey['attribute2'])
-         {
-         $registerform .= "<tr><td align='right'>".$thissurvey['attribute2'].":</td>\n"
-         ."<td align='left'><input class='text' type='text' name='register_attribute2'";
-         if (isset($_POST['register_attribute2']))
-         {
-         $registerform .= " value='".htmlentities(returnglobal('register_attribute2'),ENT_QUOTES,'UTF-8')."'";
-         }
-         $registerform .= " /></td></tr>\n";
-         }        */
+		
+        //GET THE CUSTOM ATTRIBUTES
+        $asExtraAttributes= GetTokenFieldsAndNames($surveyid, true);
+        $asExtraKeys = array_keys($asExtraAttributes);
+
+        foreach ($asExtraKeys as $sKey) 
+        {
+            $registerform .= "<tr><td align='right'>".$asExtraAttributes[$sKey].":</td>\n"
+            ."<td align='left'><input class='text' type='text' name='register_$sKey' ";
+            if (isset($_POST["register_" . $sKey]))
+            {
+                $registerform .=  " value='".htmlentities(returnglobal("register_" . $sKey),ENT_QUOTES,'UTF-8')."'";
+            }
+            $registerform .= " /></td></tr>\n";
+        }
+
         $registerform .= "<tr><td></td><td><input id='registercontinue' class='submit' type='submit' value='".$clang->gT("Continue")."' />"
         ."</td></tr>\n"
         ."</table>\n"
Index: register.php
===================================================================
--- register.php	(revision 9503)
+++ register.php	(working copy)
@@ -107,19 +107,29 @@
 
 $postfirstname=sanitize_xss_string(strip_tags(returnglobal('register_firstname')));
 $postlastname=sanitize_xss_string(strip_tags(returnglobal('register_lastname')));
-/*$postattribute1=sanitize_xss_string(strip_tags(returnglobal('register_attribute1')));
- $postattribute2=sanitize_xss_string(strip_tags(returnglobal('register_attribute2')));   */
 
+//Geting the custom attributes
+$asExtraAttributes= GetTokenFieldsAndNames($surveyid, true);
+$asExtraKeys = array_keys($asExtraAttributes);
+
+$asFields = array($postfirstname, $postlastname, returnglobal('register_email'), 'OK', $newtoken);
+
+$sQuant_params = "";
+$sName_fields = "";
+foreach ($asExtraKeys as $sKey) 
+{
+    $sQuant_params .= ", ?";
+    $sName_fields .= ", " . $sKey;
+    ${"register_" . $sKey} = sanitize_xss_string(strip_tags(returnglobal("register_" . $sKey)));
+    $asFields[] = ${"register_" . $sKey};
+}
+
 //Insert new entry into tokens db
 $query = "INSERT INTO {$dbprefix}tokens_$surveyid\n"
-. "(firstname, lastname, email, emailstatus, token)\n"
-. "VALUES (?, ?, ?, ?, ?)";
-$result = $connect->Execute($query, array($postfirstname,
-$postlastname,
-returnglobal('register_email'),
-                                          'OK', 
-$newtoken)
-//                             $postattribute1,   $postattribute2)
+. "(firstname, lastname, email, emailstatus, token". $sName_fields .")\n"
+. "VALUES (?, ?, ?, ?, ?". $sQuant_params .")"; 
+
+$result = $connect->Execute($query, $asFields) 
 ) or safe_die ($query."<br />".$connect->ErrorMsg());  //Checked - According to adodb docs the bound variables are quoted automatically
 $tid=$connect->Insert_ID("{$dbprefix}tokens_$surveyid","tid");
 
patch_crystalblood.patch (4,100 bytes)
Mazi

Mazi

2010-11-23 16:02

partner   ~13588

Carsten, this is an often requested feature by our users. Can you please have a look?!

Thanks!

CrystalBlood

CrystalBlood

2010-11-23 17:44

reporter   ~13592

What do yo think about te code attached? you consider that may help? it works for me.. 8-)

c_schmitz

c_schmitz

2010-11-23 19:22

administrator   ~13597

Last edited: 2010-11-23 19:44

View 2 revisions

In general it looks okay, but the patch assumes that by default all attribute fields are visible in the register page. There should be a way to configure what fields are visible in the rgister page (would be best in the attribute field configuration). Could you do that?

Please note that we feature-freeze for 1.91 soon so we would need your updated patch within the next 5 days.

CrystalBlood

CrystalBlood

2010-11-24 21:38

reporter   ~13602

Last edited: 2010-11-25 15:31

View 2 revisions

It will be a honor to help, to accomplish this task i propose to add another field in the tokens_xxxx table, with the syntax simmilar to the attributes fields, something like this:

attribute_1=yes
attribute_2=no
attribute_3=yes

So it's a way to show the fields in the registration form (register.php) and in the tokens management (tokens.php), we display with a checbox if shows or not.

Another idea?

Now i find myself with little time (finals in college), i don't think that 5 days will be sufficient, but if you want i'll do it! sooner or later.. hehe

CrystalBlood

CrystalBlood

2010-12-20 00:51

reporter   ~13815

Now i'm free, and i have time if you wish i'll acomplish this issue!

Another proposal may could be adding to the existing extra attribute field another token after the value, something like this:

attribute_1=College=yes
attribute_2=Phone Number=no
attribute_3=Social Number=yes

what do you think?

Greetings!

c_schmitz

c_schmitz

2010-12-20 16:28

administrator   ~13816

I think that sounds great. Make sure your patch will be based on
https://limesurvey.svn.sourceforge.net/svnroot/limesurvey/source/limesurvey_dev and it should be created with SVN diff.

Also make sure it is backward compatible (defaults to 'no') after the installation was upgraded.

Mazi

Mazi

2011-03-17 23:16

partner   ~14459

CrystalBlood, any news on this? It would be really great to have this feature at one of the next Limesurvey versions.

c_schmitz

c_schmitz

2011-03-28 02:28

administrator   ~14581

CrystalBlood?

CrystalBlood

CrystalBlood

2011-03-28 13:31

reporter   ~14586

Sorry c_schmitz and Mazi!
I'm in college exams!
My activities on this issue were frozen for a moment.
No problem if you wait a little longer? or you are in a great hurry?

Mazi

Mazi

2011-03-28 15:34

partner   ~14588

Thanks for getting back in touch with us. We prefer a tested, working solution so there is no problem if it takes a little longer. We are very happy that you are working on this!

Issue History

Date Modified Username Field Change
2010-11-19 19:04 CrystalBlood New Issue
2010-11-19 19:04 CrystalBlood File Added: patch_crystalblood.patch
2010-11-23 16:02 Mazi Note Added: 13588
2010-11-23 16:02 Mazi Assigned To => c_schmitz
2010-11-23 16:02 Mazi Status new => assigned
2010-11-23 17:44 CrystalBlood Note Added: 13592
2010-11-23 19:22 c_schmitz Note Added: 13597
2010-11-23 19:44 c_schmitz Note Edited: 13597 View Revisions
2010-11-23 22:08 c_schmitz Status assigned => feedback
2010-11-24 21:38 CrystalBlood Note Added: 13602
2010-11-24 21:38 CrystalBlood Status feedback => assigned
2010-11-25 15:31 CrystalBlood Note Edited: 13602 View Revisions
2010-12-20 00:51 CrystalBlood Note Added: 13815
2010-12-20 16:28 c_schmitz Note Added: 13816
2011-03-17 23:16 Mazi Note Added: 14459
2011-03-28 02:28 c_schmitz Note Added: 14581
2011-03-28 02:28 c_schmitz Status assigned => feedback
2011-03-28 13:31 CrystalBlood Note Added: 14586
2011-03-28 13:31 CrystalBlood Status feedback => assigned
2011-03-28 15:34 Mazi Note Added: 14588
2012-06-21 14:14 c_schmitz Status assigned => closed
2012-06-21 14:14 c_schmitz Resolution open => fixed
2012-06-21 14:14 c_schmitz Fixed in Version => 2.00