Login | Sign up | Toll-Free: 1-800-752-0455



4 posts by 2 authors in: Forums > CMS Builder
Last Post: November 14

By Zicky - November 2 - edited: November 2

I have a multi section editor for "Students" and another for "Notes".

Each student is given an ID number.

In the "Students" multi section editor there is a "Related Records" which calls to "Notes" and allows the editor to "Modify, Erase, and Create" new / ongoing "Notes" records and assign the note created to a student.

In "Notes" I have a field type "List" which allows the editor to assign the student's ID Number by selecting the student's name. This works, however the list of students is long and it's a bit of a headache selecting the student from the list of students just to assign the student's ID Number to the Note record being created.

So my question is -

Is it possible to automatically get the "Student's ID Number" (via the related record's click to create a note for a student) at the moment the related record is being created and plug the value of the Student's ID# into the "Notes' Student Name/ID field", so that there is no need to select the student from the dropdown list of students in the "Notes" section? Thereby reducing the amount of effort needed to create a related record in Notes for a Student.

I hope I explained that well.

Thanks, Zicky

Hi Zicky, 

If you click "Create" under your related records section and then look in the URL, there should be a field named "yourtableNum".  If you name your field with that name it should get auto-populated.  

Hope that helps!

Dave Edis - Senior Developer

Hi Zicky, 

There's no easy way to do that.  You could perhaps write a plugin that that checked for yourtableNum in _REQUEST and then populated the values.  

Actually, I ended up writing it for you.  Try this (relatedRecordsFieldPopulator.php): 

Plugin Name: Related Records Field Populator
Description: Populate additional fields when adding records with related records
Version: 1.00
CMS Version Required: 3.11

addAction('record_preedit', function($tableName, $recordNum) {
  $parentTable = 'every_field_multi'; // this is the table with a related records field      
  $childTable  = 'accounts';          // this is the table that gets added to
  // skip unless adding related record to target table
  $parentNumField  = $parentTable . "Num"; // this visible in the url
  $parentRecordNum = isset($_REQUEST[$parentNumField]) ? $_REQUEST[$parentNumField] : '';
  if ($tableName != $childTable || !$parentRecordNum) { return; } 
  // load record
  $parentRecord = mysql_get($parentTable, $_REQUEST[$parentNumField]);
  if (!$parentRecord) { return; } // skip if no parent record

  // pre-populate fields with the same name
  foreach ($parentRecord as $key => $value) {
    if (isset($_REQUEST[$key])) { continue; } // skip if already set
    $_REQUEST[$key] = $value;
  // set some custom fields
  if (!isset($_REQUEST['customChildFieldName'])) { // if not already set
    $_REQUEST['fullname'] = $parentRecord['title'];


// eof

Hope that helps!

Dave Edis - Senior Developer