Forums

Help - populating form fields from database, update record

matthewcostello 06 Sep, 2009
I have two forms

1) The first form captures basic registration information. Logs it to the database and connects to the Joomla Registration Plugin.

All of this is performing successfully. Data is being captured, Joomla registration is complete.

2) the second form. I want to be able for the registered user to Upgrade their account which requires more information and therefore updating the table.

Ideally the go to another form based on the first but requiring more data. I would like the existing data to populate into the appropriate fields and then allow the user to add additional data, which, onSubmit, would update in the database.

I have tried the following and cannot get the form to auto - populate.

I am using the Profile Plugin - it is set up under the Plugin tab,
I click on the Profile Page link with my form checked on the Forms manager page.
Profile Page is configured with the right table chosen,
Target Field Name = cf_user_id
and my ‘Request’ parameter name is user_id

I have add a hidden field to the form: <input type="hidden" name=" cf_user_id " id=" cf_user_id " value="{cf_user_id}" />

I log in as a registered user, click on the “Upgrade” link.

The form appears but no data is populating the field.

What am I missing?

Thanks for your help.
GreyHead 06 Sep, 2009
Hi mathewcostello,

The Profile plugin is intended to work by being called from a URL with an id value included in it as e.g. &cf_user_id=999

The {field_name} syntax won't work in the Form HTML - not least because at that stage cf_user_id doesn't have a value. But you can get the user id from the Joomla User Object - if you search here on 'getUser' you will find many, many posts on how to do this.

How are you passing users to the second form? If it's just an 'ordinary' form then you can add some code to the beginning of the Form HTM to look up the user values in your table and set the input values accordingly.

Bob
matthewcostello 07 Sep, 2009
Thanks for the quick reply.

The second form is being reached via a menu item in a registered users menu. Since the user id will vary, the link will need to contain a dynamic variable id. SO I use and External link via the Menu Manager and add user_id="<?php $user = &JFactory::getUser();echo $user->id;?>" But I get mush in the actual URL.

So, I'm unclear, how a variable (user-id) can be included in a menu link. I've searched on this but haven't come up with anything conclusive.

Thanks for your help.
GreyHead 07 Sep, 2009
Hi matthewcostello,

I don't think you can use a variable in a menu link. I'd create a form with no fields so that it displays just fixed content and use getUser and a MySQL query at the beginning to pre-load the necessary info.

Bob
This topic is locked and no more replies can be posted.