How do I automatically fill in a record field with the users name?
3 posts by 2 authors in: Forums > CMS Builder
Last Post: July 15, 2014 (RSS)
By willydoit - July 14, 2014
Hi all,
I feel that what I want to do is very simple but it's probably that simple that there's only me that needs to be told how to do it.
I am creating a basic blog facility, or at least trying to, on my viewer listing page I want viewers to be able to filter blogs by their author, however in order to do this I feel I need to auto populate each blog record with the users name at the time of creation. To avoid potential spelling anomalies I want to automatically pull the users name from the user account and populate each blog record with it when it is created. So basically, as well as adding the users record number I also want to include their "fullname" field so that it can be seen within the user blog record and can therefore form part of a filter search by the viewer.
I am aware that each record created is linked to a user via the user number ( createdByUserNum ) but how do I pull the name associated with that number to auto populate an "author" field in the blog record.
In my "User Accounts" section each record has a "fullname" field, In my "Blogs" section each blog created has an "author_id" field. The "author_id" field in the blog table needs to be the content of the "fullname" field from the "User Accounts" table, how do I achieve this please, I have accomplished something similar which produced a linked drop down list of users to choose from but that isn't any good as we don't want people to be able to create blogs under another users name so it has to be auto populated with the actual users full name.
Hopefully this makes sense.
Thanks in advance for any help provided.
By claire - July 15, 2014
Hi Willy
Are you using the Website Membership plugin? This is very easy if you've got that running. Basically, on every page load, you have access to an array called $CURRENT_USER, which has just about everything you need.
When a user is creating a blog, you can auto-fill createdByUserNum and author_id with what you need from $CURRENT_USER when the form is submitted.
I suspect this will solve your other problem with the filter too. Let me know what you think.
Claire Ryan
interactivetools.com
Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
By willydoit - July 15, 2014
Hi Claire,
thanks for all the time you are putting in on this, it is appreciated. I dont think we have membersship plugin as such as we did have a number of elements on this site written specially for us by yourselves which provides similar functionality so it may be based on the membership plugin or be a precursor to it.
A number of years ago you created a user signup facility which would allow users to sign up for different products which would create them an account inthe appropriate tables.
I am not sure what info you would need to determine what was set up for us but I will set up an ftp account for you and email you the details to support@ in the next 30 minutes, it's 22:30 here but I need to get this sorted asap so will try to sort everything via my ipad. Hopefully that will give you access to all you need to see what we have in place.
Thanks again.