Populating multiple fields from pulldown list
5 posts by 2 authors in: Forums > CMS Builder
Last Post: February 25, 2016 (RSS)
By lozzer - February 22, 2016
I have a slightly tricky query to explain!
I have a CMSB setup which has a 'report' section, where performance is recorded for an individual person at several times. The report only contains four fields (First Name, Last Name, Date of Birth and ID) relating to the person, with a further dozen fields for each 'performance'. Rather than having to input those four fields each time, I'd like to be able to select an individual from a pulldown list in the Section Editor to populate those four blank fields.
I have been able to get the pulldown list working OK using the following MySQL query:
<?php $numValue = (@$ESCAPED_FILTER_VALUE )? $ESCAPED_FILTER_VALUE : '0'; ?>
SELECT num, CONCAT(FirstName,' ', LastName, ' [', ID,']')
FROM `<?php echo $TABLE_PREFIX ?>report`
WHERE num != <?php echo $numValue; ?>
But I cannot figure out how to make the selection populate then populate those four fields. Any help gratefully received!
Hi lozzer,
It would be possible to create a system that does this, but you'd need to build a small plugin to add the values when the user saves the record. You'd be able to do this with the plugin hook record_postsave.
Is there a particular reason you need this information added to the performance record if it's already stored against the person record? The best solution seems to be to have a single drop down field where you select the user, and it displays the their first name, last name, DOB, then you wouldn't need to have the extra fields. Also, if a user changes their name, you wouldn't have to go through each performance record and update the name field as well.
Let me know if you have any questions.
Cheers,
Greg
PHP Programmer - interactivetools.com
By lozzer - February 24, 2016
Hi Greg,
The information is being transferred from large CSV files where the data is already in this format - records with personal data and performance data combined.
Once this data has been transferred over, I'd like to be able to enter new performance data for an individual who already has a record without having to enter their personal data (ID, First Name, Last Name, DOB) again; but the option needs to remain to enter this information manually for new individuals, if that makes sense.
I'm just getting started with MySQL stuff. Is this something I can hire one of you guys to write?
Thanks, Lozzer
Hi lozzer,
This is something we would be able to help with. if you email consulting@interactivetools.com with the details of the site, we can give you an estimate for either creating a plugin to add the missing details, or to import the CSV data so that those fields aren't required.
Let me know if you have any questions.
Cheers,
Greg
PHP Programmer - interactivetools.com
By lozzer - February 25, 2016
Thanks Greg. I've had a couple of emails from Ross, so I hope we'll get it sorted! Lozzer