The following warnings occurred: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Warning [2] Undefined array key "avatartype" - Line: 783 - File: global.php PHP 8.1.31 (Linux)
|
Store Account Id of Submitting User in Submission - Printable Version +- Form Tools (https://forums.formtools.org) +-- Forum: Form Tools (https://forums.formtools.org/forumdisplay.php?fid=1) +--- Forum: General Discussion (https://forums.formtools.org/forumdisplay.php?fid=5) +--- Thread: Store Account Id of Submitting User in Submission (/showthread.php?tid=2940) |
Store Account Id of Submitting User in Submission - grahame - Mar 9th, 2014 Hi Formtools 2.2.6 A bit of a newbie with Formtools but I dabble with PHP/MySQL. I have been building Internal Forms. So I understand that my users will login to Formtools, choose a form, complete the questions and submit it… At some stage an ft_form_xx table is built to store the submitted answers (where xx is form_id). All great so far! What I want to do, however, is store the details of the user submitting the form so that I can later retrieve their email and so on (i have added the extended account fields module). As far as I can see, I probably need to store their account_id from ft_accounts and add it into the ft_form-xx tables as they submit their form. I've been reading up on the general concepts here:- http://forums.formtools.org/archive/index.php/thread-898-1.html but I'm still a little in the dark… so a couple of questions please: Q1. - How can I ensure the ft_form_xx tables get created with an extra column 'account_id' automatically (I don't want my form builders to have to remember to add this as a field manually)? Q2. - Out of the 100's of files on my web server, where do I grab the session variables (incl account_id) and push them into the intended ft_form_xx/account_id column as the form is submitted? I am guessing I need to add some PHP code in one of the /public_html/formtools/admin/forms files? Ahh yes, but which one? :o) Thanks in anticipation RE: Store Account Id of Submitting User in Submission - grahame - Mar 10th, 2014 Ok I have found and installed the Hooks module which looks useful! In an effort to teach myself how this fits together, added the following code as PHP and a Template Hook on:- forms/add/index.tpl - add_form_page $account_id = $account_info["account_id"]; $extended_settings = ft_get_account_settings($account_id); print_r("account id=".$account_id); Alas, when going to the Add Form page, I get the text part of the message but no account_id? Any advice please? Thanks RE: Store Account Id of Submitting User in Submission - grahame - Mar 10th, 2014 Hi I am getting so close I can taste it! I have manually added a text field, account_id, to my form then changed my hook to a Code Hook in ft_create_blank_submission,end Code: $account_id = $account_info["account_id"]; Eh voila! My account_id field gets updated with the "Account_ID=" text ….but still not the $account_id….. So anyone know how I grab the account_id of the currently logged in user please? Thanks RE: Store Account Id of Submitting User in Submission - Joe - Mar 10th, 2014 Hey Grahame, Reading through your thread I think connecting to an external form and using the http://modules.formtools.org/submission_accounts/ might be a better route to take. You might want to take a quick look at it. Cheers, Joe RE: Store Account Id of Submitting User in Submission - grahame - Mar 10th, 2014 Hi Joe Thanks for the reply. I did have a quick look at that but in the meantime I seem to have cracked my problem. For anyone else who needs this, here's the code in my hook:- Code: $account_info = ft_get_account_info($_SESSION["ft"]["account"]["account_id"]); Now I am off to crack the Enigma Code!! :o) Thanks RE: Store Account Id of Submitting User in Submission - grahame - Mar 11th, 2014 And to automatically add an account_id field to a form I used: Code: $table_prefix = "ft_"; HTHs someone... RE: Store Account Id of Submitting User in Submission - Joe - Mar 11th, 2014 Awesome! Thanks for posting your solution Grahame! Cheers, Joe RE: Store Account Id of Submitting User in Submission - grahame - Mar 12th, 2014 Hi It turns out there is a little more to do to get this working productively. When the admin creates a new form, I think a 'default' view is also created. Now although the Account_ID column has been added OK, you still cannot use it in the 'default' view because the new column has not been assigned to that view. So… again, in the ft_finalize_form,end hook, first add the new column to the form_fields table: Code: $table_prefix = "ft_"; Code: $query = "INSERT INTO {$table_prefix}view_columns (view_id,field_id,list_order, is_sortable,auto_size,custom_width,truncate) Please keep in mind, I'm a newbie at Formtools, so check everything carefully!! RE: Store Account Id of Submitting User in Submission - Joe - Mar 13th, 2014 Thanks for posting back to the Forum. We love it when our users try out new code and post back their updates. Cheers, Joe |