load record into fields based on drop down

CyborgPrime 02 Dec, 2016
Hello-
Man, I have been scouring this forum for days and all I could find was incomplete info on this.

In order to learn how to do this, I setup a very simple 2-page form that hooks into an external database.

The database looks like this:
user_id, first_name, last_name
0, jeff, smith
1, tom, jones
2, joe, shmoe

For this example, I only want to load a textbox with the last_name depending on the first_name chosen in the drop down.

So if I choose tom from the drop-down, I want jones to display in the textbox.

The first page loads first names into a drop down from an external database - got that part done and working

The second page is supposed to just show the person's last name from the database, I got the field showing but I have no idea how to get the user_id from the drop down selection into a db read that fills the last_name box with the proper last name.

Any Suggestions would be GREATLY appreciated.

Thanks in advance.
Max_admin 02 Dec, 2016
Hi,

If the dropdown values are the users ids then you can have a "db read" configured to load the data using the dropdown's field name, add this code in the "Conditions" box:

<?php return array("table_field" => $form->data["dropdown_field_name"]); ?>

and disabled the "Enable Model ID" setting.

Best regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
CyborgPrime 02 Dec, 2016
yes, the drop down menus are user_id as the value

Thank you - i will see if I can get this to work and if it does I will post a tutorial for your review.
CyborgPrime 02 Dec, 2016
yay! It worked!

I'll write up a tutorial and submit it for approval - you fixed 2 days of forum-scouring just like that!
CyborgPrime 05 Dec, 2016
hmm.. everything worked, but when I saved this recalled record, it added a record instead of overwriting the one being displayed.

How do i make db save overwrite the record being displayed?
CyborgPrime 05 Dec, 2016
I think I found the answer: set FORCE SAVE to YES?
GreyHead 05 Dec, 2016
Hi CyborgPrime,

You need to make sure that the data set you are saving includes the primary key value for the record you want to update.

Bob
CyborgPrime 05 Dec, 2016
1 Likes
I figured it out - for some reason I couldnt get it to work, then I realized I still had force save to yes.

I added a text field so i could see that the event_id was loading, unchecked force save and now everything works!
Thanks again!
CyborgPrime 07 Mar, 2017
ok - I guess I'm just dumb..

I have gone back and used this form as an example for a new one - but there is something I am missing.

I have a dynamic drop down that is loaded with names and id's from a database. This works fine.

When I select a name and submit, it is supposed to go to page 2 and fill in the form fields with data from the record selected from the drop down.

According to the debugger, everything up to this point is normal and working (the event name and event id are showing up). Page 2 comes up the fields are just empty.

But how do I load the event name into a field on the second page? I setup a DB read (thisEvent for data id) and I tried making a field called event_name, hoping it would pick it up automatically, but that doesnt seem to work.

A closer look at the example form I made shows that I couldn't get fields working there either and I ended up just hard-coding custom scripts to fill the fields.

I'd like to do it the proper Chronoform way.... What am I doing wrong?


Array
(
    [option] => com_chronoforms5
    [chronoform] => OHEventForm
    [event] => page2
    [eventSelected] => 898
    [button7] => Submit
    [thisEvent] => Array
        (
            [event_id] => 898
            [event_name] => Santa Fe Renaissance Faire - DEMO
        )

)
CyborgPrime 07 Mar, 2017
Answer
Figured it out - I had the Model ID set on the second page.

Turning it off, and setting the conditions to:


<?php
return array('event_id' => $form->data['eventSelected']); 
?>


It now works.

This has given me the inspiration to fix the first form I did.

Thanks anyhow!
This topic is locked and no more replies can be posted.