Forums

Post different user data to different database table

yigal 13 Aug, 2009
Hi,
I'm trying to integrate submission of data to user-specific table in database.
meaning, every user will have the same form that will write the data to a different table in database. So I can see in the database all data from the same user in one table.
Next step, is to create file-upload field which is user-specific too, meaning each user will have a directory where all his uploaded files are.

Any chance to do that in chrono?
GreyHead 13 Aug, 2009
Hi yigal,

Both of these are possible, I'll need to look a little at the file upload.

Having a different table for each user doesn't sound like a good idea - it can get difficult to manage. Better to put all the data in the same table and use a user_id column to identify who it belongs to.

Bob
nml375 13 Aug, 2009
Hi,
Regarding the first question, I'd got with Bob. It's fully possible, but you'd have to write your own db storage code instead of the autogenerated one.

As for your second question, my recommendation is to use the "FileName Format" setting, and include some code to either insert the directory to the $filename variable, or alter the 'uploadpath' form parameter. I suppose both approaches could be considered a dirty hack though, and you'd have to make sure each users' upload directory exists.

I believe either of the codes below should do the trick:
$filename = JFactory::getUser()->username . DS . date('YmdHis').'_'.\$chronofile['name'];

$MyForm->setFormParam('uploadpath', $MyForm->formparams('uploadpath') . DS . JFactory::getUser()->username . DS); $filename = date('YmdHis').'_'.\$chronofile['name'];


/Fredrik
yigal 16 Aug, 2009

Hi yigal,

Both of these are possible, I'll need to look a little at the file upload.

Having a different table for each user doesn't sound like a good idea - it can get difficult to manage. Better to put all the data in the same table and use a user_id column to identify who it belongs to.

Bob



Sounds good, so how do I insert a user_id column to the table?
yigal 20 Aug, 2009
Sorry bob,
I'm no programmer,
could you just let me know how to insert the user-id info into a column in that table? I guess it's just a piece of code I should put somewhere.
yigal 01 Dec, 2009

$filename = JFactory::getUser()->username . DS . date('YmdHis').'_'.\$chronofile['name'];



Thank you Fredrik!
This did the trick like a charm, It even creats the directories for each user automatically as they upload.
firestarter 11 Dec, 2009
$filename = JFactory::getUser()->username . DS . date('YmdHis').'_'.\$chronofile['name'];

I really don't understand how this code did the trick. it returns only the current logged in username and the date for me when I placed in onsubmit code-after email. I think I'm doing something wrong and there are missing parts of the puzzle and I stuck. the code I need should create a folder named by current user and save the user's uploaded file into this folder. I'm not a coder and I guess it is not that hard to do for a pro.
GreyHead 11 Dec, 2009
Hi firestarter,

That code will only work in the ChronoForms File Uploads tab. If you are using some other file uploader than it will do nothing for you.

Bob
yigal 13 Dec, 2009
Hi Firestarter,
As Bob mentioned, the code needs to go in "FileName Format" setting in the File Upload tab, and not in the onsubmit.

Yigal
firestarter 14 Dec, 2009
it worked like a charm in the end. the mistake was mine. I forgot to add 'enctype="multipart/form-data"' to form tag attachment textbox. thanks for your support.
This topic is locked and no more replies can be posted.