We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8274 ☆ A M B ☆
    • 222 Posts
    Is there a way process two (or more) tv fields in a formtab to a single string before it is saved to a custom db table?

    I am building a product spec manager, and I want to have two drop downs (the first is a list of types: like pad, tip, electrode; the second is a list of parameters: length, diameter, size).

    On submit, I want the "name" record to concat the two values into a single string, like "pad size" or "tip length".

    If there is a way, what is the best way to set that up in the migxdb config -> formtabs?

    This question has been answered by Bruno17. See the first response.

    [ed. note: dvstudiosinc last edited this post 12 years, 6 months ago.]
    • discuss.answer
      • 4172
      • 5,888 Posts
      you will need two custom processors:

      custom update - processor:

      before this line:
      $object->fromArray($postvalues);


      add something like:

      $name = array();
      $name[] = $modx->getOption('type',$postvalues,'-');
      $name[] = $modx->getOption('parameter',$postvalues,'-');
      
      $postvalues['name'] = implode(' ',$name); 


      custom fields - processor:

      at the end after the foreach-loop add this:

      if (isset($record['name'])){
          $name = explode(' ',$record['name']);
          $record['type'] = $name[0];
          $record['parameter'] = $name[1];
      }


      If the values of the second listbox are depending of the selection of the first listbox,
      you can use the dynamicDropdown - TV to set the listboxes up.


        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 8274 ☆ A M B ☆
        • 222 Posts
        I had assumed I was getting into the custom processors, but looking at the processors in the migx folder, I was having a time figuring out where to inject my field concat.

        This makes sense and confirms what I was thinking (and removes the need for extra db fields as was my fall back)

        Thanks
          • 8274 ☆ A M B ☆
          • 222 Posts
          I copied the update.php and fields.php to my components processor/mgr folder, and updated as you recommended, but it is not working... in that a new record doesn't save the name field, and I can't update a record (where I manually entered the name into the db field).

          My error log shows a "Unknown column 'productOptions.resource_id' in 'where clause'" error.

          Any ideas what might be set wrong?

            • 8274 ☆ A M B ☆
            • 222 Posts
            So I figured out that migxdb is NOT looking in my custom processors path I supplied, just in the default.

            HOw do I force it to look in the path of core/components/mymigxcmp/processors/mgr/options/?

            My class has 5 db tables, so I need to have subfolders in mgr to differentiate the processors.
              • 4172
              • 5,888 Posts
              put into the MIGXdb setting

              processors path > options
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!