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/