Tracking User Info of Form Submitter

Permalink 1 user found helpful
Hi there, is there currently a sleek way within Concrete5 to track who is submitting a form automatically?

My forms are within a user-authenticated area but when I look at reports it doesn't tell me anything about the user who submitted the form.

I thought I might try to make a custom template for the form block and use the UserInfo call to fill in an extra hidden field. Then it occured to me : Would this hidden field automatically appear in the report?

Any suggestions?

fridayphoto
 
Mnkras replied on at Permalink Reply
Mnkras
yea i think a hidden field should show up, but i would also do some "reinforcing" to make sure they can't change their id or whatever via firebug
fridayphoto replied on at Permalink Reply
fridayphoto
Got the hidden field part working fine with the form template. But .... it still doesn't show up in the report.

To make the form template :

Copy the 'view.php' from '/concrete/blocks/form' into a new folder '/blocks/form/templates/poll/' and then added a bit of code to it :

<?php
Loader::model('userinfo');
$u = new User();
$ui = UserInfo::getByID($u->uID);
?>
<input name="UserName" type="hidden" value="<?= $ui->getUserName(); ?>" />


Once that's saved and uploaded, I right-clicked on the block in question on the site and hit 'Change Template' and so forth.

Still not funtional though! How do I force something to show up in the report? Must be in the database or something.
matogertel replied on at Permalink Reply
matogertel
you need to add the field to the form block just like any field, make it for example a text field.
Then in your custom template make sure that field is hidden, and it has the user id as it's value. You'll need to duplicate the loadSurvey function in your view.php in order to achieve this. I'm thinking about adding this a standard feature of the community form block, since I've used it in a few sites and I've seen people asking for it.
fridayphoto replied on at Permalink Reply
fridayphoto
Hey thanks man! I knew it would be possible somehow. Unfortunately, I'm not able to implement your suggestions without a bit more coaching.

I understand that I'd need to duplicate this line :
<?php  $miniSurvey->loadSurvey( $survey->questionSetId, 0, intval($bID) );  ?>

But what would the syntax of the duplicate be? I cracked open the form/controller.php but wasn't able to discern the exact use. Any help would be greatly appreciated.
fridayphoto replied on at Permalink Reply 1 Attachment
fridayphoto
Figured it all out.

The simplest method involved :

1. Adding the 'Username' text field normally
2. Creating a new 'switch' entry for the 'loadInputType' function in /blocks/form/controller.php
case 'username':
  $u = new User();
  Loader::model('userinfo');
  $ui = UserInfo::getByID($u->uID);
  return '<input name="Question'.$msqID.'" type="hidden" value="'.$ui->getUserName().'" />';

3. Manually changing the inputType in the 'btFormQuestions' table to 'username'.

I also duplicated the 'loadSurvey' function in controller.php to 'loadVoting' and hacked it apart to customize the look of the forms. Worked well. I created a custom template for the form to reference this new function instead of loadSurvey.

Presto!