We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 39498
    • 169 Posts
    I am using migxdb according to this tut:
    http://rtfm.modx.com/display/ADDON/MIGXdb.Manage+Events-Resources+in+a+CMP+with+help+of+MIGXdb

    I wonder how to validate the date tvs. Where to implement some rules?
      • 39333
      • 151 Posts
      You might try the suggestions in this thread:

      https://forums.modx.com/index.php?topic=67378.0
        MODX...the Zen of CMS
        "Bight off more than you can chew and keep right on chewing."
        • 4172
        • 5,888 Posts
        the simplest way for validation is this.
        Create a custom-update-processor with something like that:


                    if (yourValidationCondition) {
                        $updateerror = true;
                        $errormsg = 'you have an error in your form.......';
                        return;
        
                    }


        just before

        $object->fromArray($postvalues);


        And please use this board:
        https://forums.modx.com/board?board=271

        [ed. note: Bruno17 last edited this post 13 years, 7 months ago.]
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 39498
          • 169 Posts
          Quote from: Bruno17 at Mar 03, 2013, 01:17 AM
          the simplest way for validation is this.

          $object->fromArray($postvalues);



          you mean in file
          migx/processors/mgr/childresources/update.php

          ?
          can not find a line
          $object->fromArray($postvalues);
            • 39498
            • 169 Posts
            So I inserted for testing suppose in line 62 of
            migx/processors/mgr/childresources/update.php

            this code
            if ($includeTVs) { 
                $myId = $scriptProperties['object_id'];
                $page = $modx->getObject('modResource', $myId);
                $myEventStart = $page->getTVValue('eventstart');
                $myEventEnde = $page->getTVValue('eventend');
            
                if (empty($myEventStart)) {  
                            $updateerror = true;
                            $errormsg = 'Sie müssen ein Startdatum setzen';
                            return;
                }
               
            }

            I do get an alert, but obviously this is not a propper solution. Three questions:
            1. I do validate the tv db values, not the form values. How to access the form values of the tvs?
            2. Is this the correct place for the validation code in the update.php?
            3. And is there a way to set the unpub_date of the ressource.


            And: Could some Admin move this tread to the migx forum. Or should I better start a new thread with that concern? [ed. note: spica8 last edited this post 13 years, 7 months ago.]
              • 4172
              • 5,888 Posts
              try this:

                      $data['context_key'] = $modx->getOption('context_key', $data, $scriptProperties['wctx']);
              
                      $myEventStart = $data['eventstart'];
                      $myEventEnde = $data['eventend'];
              
                      if (empty($myEventStart)) {
                          $updateerror = true;
                          $errormsg = 'Sie müssen ein Startdatum setzen';
                          return;
                      }
              
                      if ($includeTVs) {
              


              but you shouldn't modify the processors, which came with MIGX for your own purposes (they will be overridden on updates), but create own custom-processors.

              There are two ways to use custom-processors in your projects:

              1.
              create a new folder in components/migx/processors/mgr/
              for example components/migx/processors/mgr/childresources_spica/

              copy all processors from /childresources/ to /childresources_spica/
              change the processorspath in your MIGX-configuration from childresources to childrecources_spica


              2.
              create a new components-folder
              for example components/childresources_spica/processors/mgr/childresources/
              and put just the modified processors into the folder.
              In this case it will use the unmodified processors from migx and if there exists custom-processors in your components-folder, it will use this one.

              put in packagename of your MIGX-configuration: childresources_spica








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

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 39498
                • 169 Posts
                Thanx Bruno, thats working out for some evaluations.

                To complete I also added this code to modifie the unpubdate according to the set dates

                        $myId = $scriptProperties['object_id'];;
                        $myResource = $modx->getObject('modResource',$myId);
                        if (empty($myEventEnde)) { 
                            $unpub_date = strtotime("+6 hours", strtotime($myEventStart));
                        } else {  
                            $unpub_date = strtotime("+6 hours", strtotime($myEventEnde));
                        };
                        $myResource->set('unpub_date', $unpub_date);
                        $myResource->save();
                  • 4172
                  • 5,888 Posts
                  you don't need to get and manipulate the Resource-object.
                  Just set the values before the script runs the resource-create/update-processor.
                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 39498
                    • 169 Posts
                    I already tried
                            if (empty($myEventEnde)) { 
                                $data['unpub_date'] = strtotime("+6 hours", strtotime($myEventStart));
                            } else { 
                                $data['unpub_date'] = strtotime("+6 hours", strtotime($myEventEnde));
                            };

                    but without effect
                      • 4172
                      • 5,888 Posts
                      I think pub_date and unpub_date should be string-formatted dates, not unixtimes here
                        -------------------------------

                        you can buy me a beer, if you like MIGX

                        http://webcmsolutions.de/migx.html

                        Thanks!