Forums

Load Form With Saved Data

hangbill 03 Apr, 2019
Hi
Have read all the posts and guides re how to do this, but am stuck.

Have a Joomla registration form that saves data to the users table as well as to a linked table that holds additional user data. This form has some conditional drop down options. Want to give users option to edit their registration data. So have made copy of the form, now need to load the current user's data into the form.
In the Setup section have added a Read Data event above the Submit section. Added 2 models (members and add_member_fields). One is for the users table and the other one for the linked table. In the Conditions box of the members model I linked the id of the users table to the user of the current session with this code
<?php $juser = \JFactory::getUser(); return array("id" => $juser -> get("id")); ?>
Form does not load user data.
Am I on the right track?

Thanks



healyhatman 03 Apr, 2019
OK so none of that PHP is necessary at all, and the syntax you have for the value with the array and everything in it is completely wrong.

If you want the user's id, just use {user:id}
hangbill 04 Apr, 2019
So is everything good except the condition?
healyhatman 04 Apr, 2019
I can't see the contents of the add_member_fields model, but sure.

But you don't even need the data read from the users table at all. Just need the add_member_fields read.

All the data for the logged in user is available with {user:field}
{user:email}
{user:name}
{user:username}
{user:whateverotherfieldisintheuserstable}
hangbill 04 Apr, 2019
Not sure I get it.
So, no conditions. Then in fields to retrieve I reference the fields in the 2 models eg
{members:name}
{members:username}
{members:password}
{members:email}
{add_member_fields:company}

This does'nt return the record

Or do I scrap the members model and use only add_members_fields (this table holds additional user data that should not go into the users table).
healyhatman 04 Apr, 2019
That's right, scrap the members model. So the condition will end up being user_id = {user:id} assuming that user_id is what you've called the foreign field in the add_member_fields table
healyhatman 04 Apr, 2019
Because all the information from the users table for the current user is available under {user:fieldname} you don't need to read it for the current user.
hangbill 04 Apr, 2019
OK, understand thanks.
Still not working but going to bed now, will pick up again in the morning. Thanks Healyhatman.
hangbill 04 Apr, 2019
Am trying different combinations, hoping to hit on something that works. Challenge is finding documentation that explains how to do it. [ol][li][em]Userid[/em] is the foreign key in [em]misc_user_addfields. [/em]Is the condition configured correctly?[/li][li]Are the fields to retrieve configured correctly?[/li][li]Anything else? [/li][/ol]
This setup config returns an error. Seems it's sees user as a field in the member model
Thanks


UPDATE
have changed the [em]fields to retrieve[/em] to
user.name
member.company
etc

No errors now but form opening without data






healyhatman 04 Apr, 2019
1. Yes that's correct
2. No that's not correct. Remove the brackets around member.company, get rid of the {user:} entries
hangbill 04 Apr, 2019
Yes, in the update comment above I did remove the brackets so, for eg now, looks like member.company, using a period not colon and no brackets. This returns empty form. So still not working but a question maybe for later - how will the users fields (name, username, email, password) be returned if I don't reference them in fields to retrieve .
healyhatman 04 Apr, 2019
Put {var:read_data#.model} in the data source of the display form action

Put{user:fieldname} in each field VALUE setting for fields corresponding with a field in the users table
hangbill 04 Apr, 2019
Think I got the first bit right => {var:read_data33.member} under data provider in the display form action.
Dont follow the 2nd advice - must this go in the read data action. Tried {user:name} in fields to retrieve and it returns and unknown column 1054 error.
healyhatman 04 Apr, 2019
NO {user:name} DOES NOT go in "fields to retrieve", NOTHING from {user:} goes in Fields to Retrieve. Other than {user:id}, what do you want to use data from the users table for?
hangbill 04 Apr, 2019
I am going to lock down username so that a registered member will not be able to change it. But other details might be changed - person might change name and email. So from the users table, both name and email must be editable. And then from the misc_user_addfields table all its fields must be editable.

So the form is an exact replica of the form that the user registered with, including all the conditional questions. Everything on the form needs to be editable, and saved back to the database, except for the username
healyhatman 04 Apr, 2019
Rightio so you can use {user:field} in your label, or the field Value, or the Placeholder, whatever you want.,
healyhatman 04 Apr, 2019
https://www.skyspider.com.au/store/shortcodes-reference

This could potentially help.
hangbill 05 Apr, 2019
Thanks for the shortcodes, appreciate it... .

Geez, I wasn't even looking at Design. I thought the whole thing was done in Setup.
Got it working for text boxes, brilliant.

Still trying to get the dropdown working, ie show the current saved value but also maintain the options if user wants to change it. The dropdowns are all saved in the misc_user_addfields table
healyhatman 05 Apr, 2019
Put the value selected in the selected box. {var:read_data#.model.field}
hangbill 05 Apr, 2019
Starting to make sense to me, now. Got this in the selected value box {var:read_data33.member.occupation} but not returning value. Have entered it correctly and there is an occupation value for the test user in the table.




healyhatman 05 Apr, 2019
You also need to have the list of options in the dropdown, do you have that?
hangbill 05 Apr, 2019
Yes the form is a copy of the original registration form so all the dropdowns are working.
I did not use label=value, just value and it saves to the db. Like this

hangbill 05 Apr, 2019
A related issue.
I sign in as userid 1033, a registered user, and open the reg form for editing. When I submit the edited form, it does not save. Debugger returns a "missing user data" error.

The foreign key in misc_user_addfields is userid. In the form design have a text field called userid and placed {var:read_data33.member.userid} in the value text box. When the form opens for editing the userid is not returned so presume this explains the missing user data messg. {var:read_data33.member.userid} is in the same format as the dropdown above so I wonder if there is an issue with this?


healyhatman 05 Apr, 2019
Copy + Paste (not screenshot) your debug output
hangbill 05 Apr, 2019
Array
(
    [chronoform] => memberregistration-edit
    [event] => submit
    [name] => tester
    [email] => tester@gmail.com
    [password] => ciu123
    [confirmpassword] => ciu123
    [userid] => 
    [ciustatus] => Associate Member
    [title] => Tester
    [occupation] => Underwriting Support
    [describeoccupation] => 
    [experience] => Senior Underwriter
    [explainexperience] => 
    [company] => xxx
    [city] => xxxx
    [province] => ON
    [country] => Canada
    [namecountry] => 
    [telephone] => 519 444 4444
    [would_you_like_otr_digital_or_mailed_] => Digital
    [address] => 
    [address2] => 
    [cityotr] => 
    [provinceotr] => 
    [postalcodeotr] => 
    [g-recaptcha-response] => 03AOLTBLQL6Pxi1L3kGu6CVEcO-G8qYwu8jXX3HaezRRFlf4AvFekJFJWdLGHxU248RESllFR4EinQlaTzTa88IkGsBRdbAQFR4lp0wRiN10-A-MY76hWiD8l70AkgJXYHizULfHfUxKUb3DI4zmub_-C0g4N9hYbzcRkAXs867XB7B8Rc-3IV10j__14KT6Tlj7A15J8QaZQ1qRlMj-ovWdbFHossOnRb8qQigRut2mEk4sB6nDjayQOKYQFivkVgJfbbRoopk_E6vs4YHXiQyIdKSnWsoer_BbvY06AXanb99M8GxMwKizZhIZhXkmjTEwAttAU_R9kR
    [button66] => 
    [0d4e14f532d92632bd557daf62d88643] => 05ca00f5a01a90c2aafeca39c7ab3062
    [c42234b300a2feaffea15712e4c1305d] => f07dbc4ff20364b07b49222c902d6079
    [joomla_user_state] => logged_in
    [Itemid] => 2033
    [option] => com_chronoforms6
    [view] => form
)
Array
(
    [google_nocaptcha27] => Array
        (
            [response] => Array
                (
                    [success] => 1
                    [challenge_ts] => 2019-04-05T11:35:40Z
                    [hostname] => www.ublizi.com
                )

            [_success] => The NoCaptcha verification was successfull.
            [var] => 1
        )

    [joomla_user15] => Array
        (
            [_error] => Missing user data.
            [var] => 
        )

)
healyhatman 05 Apr, 2019
[_error] => Missing user data.
So what';s going on here? You're saving a new user or logging a user in?
hangbill 05 Apr, 2019
Tester is a person who is already registered, logs in, and now wants to edit his registration details - say has changed company, or changed occupation , changed email etc.
This form, which is a copy of the original registration form, opens with all the user's saved data and is ready to be edited. User makes the changes and saves new values to db
healyhatman 05 Apr, 2019
Well you can't use the Save Joomla User action, that creates a new user. You need to use a save data action set to update on the #__users table
hangbill 05 Apr, 2019
Will need to update both users and misc_users_addfields tables
I will try figure it out - thanks for the pointer.
hangbill 06 Apr, 2019
Got it half working. User logs in. The edit form opens and shows the logged in user's name, username and email (not the password though, not sure if I should include the password field in this edit form). But it does not show values from the misc_users_addfields table.

Removed the Joomla Save User and replaced with 2 Save Data actions => one for the users table and one for the misc_user_addfields table. But before figuring how to save record must first solve how to open form that pulls all values from the 2 tables and shows the values on the form. So that the user can edit the data.












Array
(
    [0d4e14f532d92632bd557daf62d88643] => 26db072984a2196e95403313a0caf03f
    [c42234b300a2feaffea15712e4c1305d] => 49fa7b5c9cf75aa5f09c226a4fcb9d4e
    [joomla_user_state] => logged_in
    [Itemid] => 2033
    [option] => com_chronoforms6
    [view] => form
)
Array
(
    [read_data34] => Array
        (
            [log] => Array
                (
                    [0] => SELECT `member`.`id` AS `member.id`, `member`.`name` AS `member.name`, `member`.`username` AS `member.username`, `member`.`email` AS `member.email`, `member`.`password` AS `member.password`, `member`.`block` AS `member.block`, `member`.`sendEmail` AS `member.sendEmail`, `member`.`registerDate` AS `member.registerDate`, `member`.`lastvisitDate` AS `member.lastvisitDate`, `member`.`activation` AS `member.activation`, `member`.`params` AS `member.params`, `member`.`lastResetTime` AS `member.lastResetTime`, `member`.`resetCount` AS `member.resetCount`, `member`.`otpKey` AS `member.otpKey`, `member`.`otep` AS `member.otep`, `member`.`requireReset` AS `member.requireReset`, `member`.`confirmpassword` AS `member.confirmpassword`, `member`.`userid` AS `member.userid`, `member`.`ciustatus` AS `member.ciustatus`, `member`.`title` AS `member.title`, `member`.`occupation` AS `member.occupation`, `member`.`describeoccupation` AS `member.describeoccupation`, `member`.`experience` AS `member.experience`, `member`.`explainexperience` AS `member.explainexperience`, `member`.`company` AS `member.company`, `member`.`city` AS `member.city`, `member`.`province` AS `member.province`, `member`.`country` AS `member.country`, `member`.`namecountry` AS `member.namecountry`, `member`.`telephone` AS `member.telephone`, `member`.`would_you_like_otr_digital_or_mailed_` AS `member.would_you_like_otr_digital_or_mailed_`, `member`.`address` AS `member.address`, `member`.`address2` AS `member.address2`, `member`.`cityotr` AS `member.cityotr`, `member`.`provinceotr` AS `member.provinceotr`, `member`.`postalcodeotr` AS `member.postalcodeotr`, `member_add_fields`.`id` AS `member_add_fields.id`, `member_add_fields`.`userid` AS `member_add_fields.userid`, `member_add_fields`.`ciustatus` AS `member_add_fields.ciustatus`, `member_add_fields`.`title` AS `member_add_fields.title`, `member_add_fields`.`occupation` AS `member_add_fields.occupation`, `member_add_fields`.`describeoccupation` AS `member_add_fields.describeoccupation`, `member_add_fields`.`experience` AS `member_add_fields.experience`, `member_add_fields`.`explainexperience` AS `member_add_fields.explainexperience`, `member_add_fields`.`company` AS `member_add_fields.company`, `member_add_fields`.`telephone` AS `member_add_fields.telephone`, `member_add_fields`.`city` AS `member_add_fields.city`, `member_add_fields`.`province` AS `member_add_fields.province`, `member_add_fields`.`country` AS `member_add_fields.country`, `member_add_fields`.`namecountry` AS `member_add_fields.namecountry` FROM `jospc_users` AS `member` LEFT JOIN `misc_user_addfields` AS `member_add_fields` ON `member`.`id` = `member_add_fields`.`userid` WHERE `member`.`id` = '1033' LIMIT 100;
                )

            [var] => Array
                (
                    [0] => Array
                        (
                            [member] => Array
                                (
                                    [id] => 1033
                                    [name] => tester
                                    [username] => tester
                                    [email] => tester@gmail.com
                                    [password] => $2y$10$W/Kk4EuZHX9vG493XeYJpu2tYaLHx9.iWvTLowVTPrZ9AwODbc642
                                    [block] => 0
                                    [sendEmail] => 0
                                    [registerDate] => 2019-04-04 12:25:03
                                    [lastvisitDate] => 2019-04-06 09:31:25
                                    [activation] => 
                                    [params] => 
                                    [lastResetTime] => 0000-00-00 00:00:00
                                    [resetCount] => 0
                                    [otpKey] => 
                                    [otep] => 
                                    [requireReset] => 0
                                    [confirmpassword] => 
                                    [userid] => 
                                    [ciustatus] => 
                                    [title] => 
                                    [occupation] => 
                                    [describeoccupation] => 
                                    [experience] => 
                                    [explainexperience] => 
                                    [company] => 
                                    [city] => 
                                    [province] => 
                                    [country] => 
                                    [namecountry] => 
                                    [telephone] => 
                                    [would_you_like_otr_digital_or_mailed_] => 
                                    [address] => 
                                    [address2] => 
                                    [cityotr] => 
                                    [provinceotr] => 
                                    [postalcodeotr] => 
                                )

                            [member_add_fields] => Array
                                (
                                    [id] => 36
                                    [userid] => 1033
                                    [ciustatus] => Associate Member
                                    [title] => tester
                                    [occupation] => Production Underwriter
                                    [describeoccupation] => 
                                    [experience] => Junior Underwriter
                                    [explainexperience] => 
                                    [company] => 
                                    [telephone] => 
                                    [city] => Waterloo
                                    [province] => ON
                                    [country] => Canada
                                    [namecountry] => 
                                )

                        )

                )

        )

)
healyhatman 06 Apr, 2019
Should be set to first matching not all matching
hangbill 06 Apr, 2019
Thanks. Still not pulling the occupation value into the form
hangbill 07 Apr, 2019
Trying now with the city field - this is not a dropdown which seems does not have a "value" element. Have put this in the city value box {var. empty:read_data34.memberaddfields.city} which returns true (I removed the underscores from the model name because the V6 manual says single word only, no special chars). Why is var empty? There is a value in the db field. Notice that if you put say xxxx in the value box it returns the literal but cannot get the value form the db.
healyhatman 07 Apr, 2019
Underscores aren't usually classed as special characters they should be fine. Post your debug please.
hangbill 07 Apr, 2019
Array
(
    [0d4e14f532d92632bd557daf62d88643] => 2ac7a84830a4e5813ef3a26c20fcff66
    [c42234b300a2feaffea15712e4c1305d] => e41b267d2efc4f8f96eab1b10b41eac9
    [joomla_user_state] => logged_in
    [Itemid] => 2033
    [option] => com_chronoforms6
    [view] => form
)
Array
(
    [read_data34] => Array
        (
            [log] => Array
                (
                    [0] => SELECT `member`.`id` AS `member.id`, `member`.`name` AS `member.name`, `member`.`username` AS `member.username`, `member`.`email` AS `member.email`, `member`.`password` AS `member.password`, `member`.`block` AS `member.block`, `member`.`sendEmail` AS `member.sendEmail`, `member`.`registerDate` AS `member.registerDate`, `member`.`lastvisitDate` AS `member.lastvisitDate`, `member`.`activation` AS `member.activation`, `member`.`params` AS `member.params`, `member`.`lastResetTime` AS `member.lastResetTime`, `member`.`resetCount` AS `member.resetCount`, `member`.`otpKey` AS `member.otpKey`, `member`.`otep` AS `member.otep`, `member`.`requireReset` AS `member.requireReset`, `member`.`confirmpassword` AS `member.confirmpassword`, `member`.`userid` AS `member.userid`, `member`.`ciustatus` AS `member.ciustatus`, `member`.`title` AS `member.title`, `member`.`member_add_fields` AS `member.member_add_fields`, `member`.`describeoccupation` AS `member.describeoccupation`, `member`.`experience` AS `member.experience`, `member`.`explainexperience` AS `member.explainexperience`, `member`.`company` AS `member.company`, `member`.`city` AS `member.city`, `member`.`province` AS `member.province`, `member`.`country` AS `member.country`, `member`.`namecountry` AS `member.namecountry`, `member`.`telephone` AS `member.telephone`, `member`.`would_you_like_otr_digital_or_mailed_` AS `member.would_you_like_otr_digital_or_mailed_`, `member`.`address` AS `member.address`, `member`.`address2` AS `member.address2`, `member`.`cityotr` AS `member.cityotr`, `member`.`provinceotr` AS `member.provinceotr`, `member`.`postalcodeotr` AS `member.postalcodeotr`, `member`.`occupation` AS `member.occupation`, `memberaddfields`.`id` AS `memberaddfields.id`, `memberaddfields`.`userid` AS `memberaddfields.userid`, `memberaddfields`.`ciustatus` AS `memberaddfields.ciustatus`, `memberaddfields`.`title` AS `memberaddfields.title`, `memberaddfields`.`occupation` AS `memberaddfields.occupation`, `memberaddfields`.`describeoccupation` AS `memberaddfields.describeoccupation`, `memberaddfields`.`experience` AS `memberaddfields.experience`, `memberaddfields`.`explainexperience` AS `memberaddfields.explainexperience`, `memberaddfields`.`company` AS `memberaddfields.company`, `memberaddfields`.`telephone` AS `memberaddfields.telephone`, `memberaddfields`.`city` AS `memberaddfields.city`, `memberaddfields`.`province` AS `memberaddfields.province`, `memberaddfields`.`country` AS `memberaddfields.country`, `memberaddfields`.`namecountry` AS `memberaddfields.namecountry` FROM `jospc_users` AS `member` LEFT JOIN `misc_user_addfields` AS `memberaddfields` ON `member`.`id` = `memberaddfields`.`userid` WHERE `member`.`id` = '1033' LIMIT 100;
                )

            [var] => Array
                (
                    [member] => Array
                        (
                            [id] => 1033
                            [name] => tester
                            [username] => tester
                            [email] => tester@gmail.com
                            [password] => $2y$10$W/Kk4EuZHX9vG493XeYJpu2tYaLHx9.iWvTLowVTPrZ9AwODbc642
                            [block] => 0
                            [sendEmail] => 0
                            [registerDate] => 2019-04-04 12:25:03
                            [lastvisitDate] => 2019-04-07 11:32:38
                            [activation] => 
                            [params] => 
                            [lastResetTime] => 0000-00-00 00:00:00
                            [resetCount] => 0
                            [otpKey] => 
                            [otep] => 
                            [requireReset] => 0
                            [confirmpassword] => 
                            [userid] => 
                            [ciustatus] => 
                            [title] => 
                            [member_add_fields] => 
                            [describeoccupation] => 
                            [experience] => 
                            [explainexperience] => 
                            [company] => 
                            [city] => 
                            [province] => 
                            [country] => 
                            [namecountry] => 
                            [telephone] => 
                            [would_you_like_otr_digital_or_mailed_] => 
                            [address] => 
                            [address2] => 
                            [cityotr] => 
                            [provinceotr] => 
                            [postalcodeotr] => 
                            [occupation] => 
                        )

                    [memberaddfields] => Array
                        (
                            [id] => 36
                            [userid] => 1033
                            [ciustatus] => Associate Member
                            [title] => tester
                            [occupation] => Production Underwriter
                            [describeoccupation] => 
                            [experience] => Junior Underwriter
                            [explainexperience] => 
                            [company] => 
                            [telephone] => 
                            [city] => Waterloo
                            [province] => ON
                            [country] => Canada
                            [namecountry] => 
                        )

                )

        )

)
healyhatman 07 Apr, 2019
{var:read_data34.memberaddfields.city}
Should definitely be working, make sure the read data is before the point you want to USE the read data.
hangbill 08 Apr, 2019
Yes, the Read Data was positioned after form display. Placed it in first position and works now.
Thanks Healyhatman.
This topic is locked and no more replies can be posted.