Forums

Fill hidden field based on db read following dropdown selection

Twincarb 26 Feb, 2017
I am in the process of setting up a form with CF5, the form has a dropdown which reads from the database a selection of vehicles.

Db where data is read from #__form_datatable_newvehicle

columns that I am interested in are: id, callsign, reg

I have setup the form in designer view with the following items.

custom - provides an area for free text at the beginning of the form

callsign - this is the dropdown which the vehicle callsign is selected from.
General Tab
Field - callsign
Field ID - callsign
options - 1=1 (I found when empty the dynamic function doesn't work.)
2=2
Empty Option - Select Vehicle
Label - Vehicle
All other options are empty on the general tab

Dynamic Data Tab
Enabled - yes
Data Path - vehicle_name
Value - callsign
Text Key - callsign
Validation and Events are both empty.
The Dynamic Dropdown is working correctly with the user being able to select the vehicle and it is saved to the DB for the form as is required.

The next field is the one which I wish to get the registration for of the vehicle selected in the dropdown.

Hidden Field - no need for it to be seen just the result saved in the database at the end.

General Tab
Field Name - reg
Field ID - reg
Value - This needs something I know.
Label - Registration

Going to the Setup Tab of the form I have the following details on the On Load Event

Custom Code - <?php
$user =& JFactory::getUser();
$form->data['name'] =& $user->name;
?>
This enters the name of the person into the form to save them from having to write it, this works correctly.

DB Read
Action Label - read_vehicle_names
Enabled - Yes
Table name - _form_datatable_newvehicle
Multi Read - Yes
Model ID - vehicle_name
Fields - id,callsign,reg

All other boxes are empty.

I believe that I need to add some php, either to the On Found box in a Custom Code box or in a Custom Code box below the DB Read and above the HTML Render box.

Despite reading plenty on the Forums and the FAQ's I am still struggling.😟 The data that is currently saved, I have got showing correctly in the front end using CC6.

Thanks in advance, Max and Bob...
I am now going to hide away and read Bob's book.
GreyHead 26 Feb, 2017
Hi Twincarb,

If the reg is unique then you could just use that as the value in the drop-down?

Bob
Twincarb 26 Feb, 2017
Hi Bob,

The vehicles are known by the vehicle name "callsign" and the reg is used to tie a vehicle to a particular callsign, the form is used to update the vehicle location.

When the user is in the vehicle overview from CC the location of the vehicle is shown and that looks for the reg as being the unique part to show the latest record in the DB.

Regards,
Dave
GreyHead 26 Feb, 2017
Hi twincarb,

So the reg is unique and you can use that?

Bob
Twincarb 28 Feb, 2017
Cheers Bob,

I have had a rethink about the information being stored in the Db, the information in the DB doesn't need to be user friendly because the CC connections will gather and display the correct information. Less data needed to be saved into the DB as well then which is one of the main reasons for changing the forms I am using.
Previous component struggled with a years worth of data, but that's due to the way it saved the information and then did it's lookups.

Regards,

Dave
GreyHead 28 Feb, 2017
Hi Dave,

That sounds like a good direction to go in. It is best practice to try not to duplicate data if it is already saved in another table.

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

VPS & Email Hosting 20% discount
hostinger