We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 49407
    • 159 Posts
    I am using the code below in a form chunk...

    [[!FormIt?
        &hooks=`saveChronicleProcessor,redirect`
        &redirectTo=`15`
        &redirectParams=`{"id":"[[!+grow.id]]"}` // <------ The placeholder isn't setting the parameter, it stays blank.
        &validate=`
            day:required:isNumber,
            week:required:isNumber,
            summary:required:minLength=^50^,
            content:required,
            publish_on:isDate,`
    ]]
    [[!+grow.id]] // <----- This line here is being output as expected.
    


    The placeholder is outputting outside of the FormIt.redirectParameter, but not inside it.

    The url looks like this; "http://cannacle.com/dashboard/view-grow?id="

    Where is the placeholder wandering off to inside FormIt?

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

      • 3749
      • 24,544 Posts
      Make sure you have the snippet that sets the grow.id placeholder above the placeholders on the page.

      Try making the placeholder tags cached. Having them uncached can delay their processing and they may not have been processed by the time the FormIt tag is parsed. If that doesn't work, try changing the grow.id placeholder into a snippet tag and have a snippet return the value you want there.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
      • I just tested this - note that the setId snippet is above the FormIt snippet - and it works as expected:
        [[setId]]
        <hr>
        <h2>Testing stuff...</h2>
        [[!FormIt?
           &hooks=`redirect`
           &redirectTo=`4`
           &redirectParams=`{"id":"[[+setId]]"}`
        ]]
        <form action="[[~[[*id]]]]" method="post">
            <input type="text" name="name">
            <input type="submit" name="submit" value="Submit">
        </form>
        

        And the setId snippet
        <?php
        $modx->toPlaceholder('setId', '123');
        return;

        Worked as expected.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 49407
          • 159 Posts
          Quote from: sottwell at Jan 01, 2015, 09:09 AM
          I just tested this - note that the setId snippet is above the FormIt snippet - and it works as expected:
          [[setId]]
          <hr>
          <h2>Testing stuff...</h2>
          [[!FormIt?
             &hooks=`redirect`
             &redirectTo=`4`
             &redirectParams=`{"id":"[[+setId]]"}`
          ]]
          <form action="[[~[[*id]]]]" method="post">
              <input type="text" name="name">
              <input type="submit" name="submit" value="Submit">
          </form>
          

          And the setId snippet
          <!--?php
          $modx--->toPlaceholder('setId', '123');
          return;

          Worked as expected.

          You're using a cached placeholder, maybe that is why. I have concerns with cached values in a dynamic environment. I already have a snippet above the FormIt call (saveChroniclePreProcessor) that's setting the placeholder. The placeholder is being output if I put it outside the FormIt redirectParams, but when inside the FormIt redirectParams (uncached) it fails to output. I even tried using a different preprocessor as you suggest. I'm not convinced that FormIt is acknowledging it.



          Quote from: BobRay at Jan 01, 2015, 05:04 AM
          Make sure you have the snippet that sets the grow.id placeholder above the placeholders on the page.

          Try making the placeholder tags cached. Having them uncached can delay their processing and they may not have been processed by the time the FormIt tag is parsed. If that doesn't work, try changing the grow.id placeholder into a snippet tag and have a snippet return the value you want there.

          My only concern with caching the value is that it will not change if the user chooses to edit a different grow. I'm not familiar with how caching placeholders works behind the scenes.

          I do like the idea to use a snippet to retrieve the grow ID. I'll try all the methods mentioned above and see which one works best for this application.

          Thanks for your insight, Susan, Bob.
          • Uncached worked the same.
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 4172
              • 5,888 Posts
              If you are setting this placeholder with the hook 'saveChronicleProcessor', this doesn't work, because has to be setted before Formit is running.
              If this is a dynamical value, you will need a uncached snippet, of course.

              This should work:
              [[!setId]]
              <hr>
              <h2>Testing stuff...</h2>
              [[!FormIt?
                 &hooks=`redirect`
                 &redirectTo=`4`
                 &redirectParams=`{"id":"[[!+grow.id]]"}`
              ]]
              <form action="[[~[[*id]]]]" method="post">
                  <input type="text" name="name">
                  <input type="submit" name="submit" value="Submit">
              </form>
              


              or create a wrapper-snippet for FormIt like:

              $redirectParams = array();
              $redirectParams['id'] = getYourIDHere();
              
              $scriptProperties['redirectParams'] = $modx->toJson($redirectParams);
              return $modx->runSnippet('FormIt',$scriptProperties);


              and call it

              [[!setRedirectParamsAndRunFormit?
                 &hooks=`redirect`
                 &redirectTo=`4`
                 &redirectParams=`{"id":"[[!+grow.id]]"}`
              ]]


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

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 49407
                • 159 Posts
                Well, I still can't get the value of [[+grow.id]] OR [[!+grow.id]] to be processed in the FormIt redirectParams.

                The saveChroniclePreProcessor snippet is setting the placeholder and I am able to output the placeholder (cached and not cached).

                The order in which the scripts are running is...
                [[!saveChroniclePreProcessor]]
                [[!FormIt?
                    &hooks=`saveChronicleProcessor,redirect`
                    &redirectTo=`15`
                    &redirectParams=`{"id":"[[+grow.id]]"}`
                    &validate=`day:required:isNumber,
                        week:required:isNumber,
                        summary:required:minLength=^50^,
                        content:required:allowTags,
                        publish_on:optional:isDate,
                        leader_url:required`
                ]]
                [[+grow.id]]
                


                When I look at the form I see the grow.id being output. Screen shot attached. The placeholder is simply not working inside the FormIt call parameter &redirectParams=`{"id":"[[+grow.id]]"}`. I get no errors. This makes no sense at all.
                  • 4172
                  • 5,888 Posts
                  that you see the processed placeholder of [[+grow_id]] in your form, doesn't mean, it is allready processed at the time, when Formit is running.

                  What is the code of 'saveChroniclePreProcessor'
                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 49407
                    • 159 Posts
                    Quote from: Bruno17 at Jan 07, 2015, 07:41 AM
                    that you see the processed placeholder of [[+grow_id]] in your form, doesn't mean, it is allready processed at the time, when Formit is running.

                    What is the code of 'saveChroniclePreProcessor'

                    saveChroniclePreProcessor
                    <?php
                    $prefix = 'xyz_';
                    $packagename = 'moarDataStuff';
                    $classname = 'Chronicles';
                    
                    $packagepath = $modx->getOption($packagename . '.core_path', NULL, $modx->getOption('core_path') . 'components/' . $packagename . '/');
                    $modelpath = $packagepath . 'model/';
                    
                    $modx->addPackage( $packagename, $modelpath, $prefix);
                    
                    $chronicle = $modx->getObject( $classname, array( 'chronicle_id' => $_GET['id'] ));
                    
                    if (!is_object($chronicle) || !($chronicle instanceof xPDOObject)) {
                        $errorMsg = 'saveChroniclePreProcessor -> Failed to create object of type: ' . $classname;
                        $modx->log(modX::LOG_LEVEL_ERROR, $errorMsg, '', 'chronicleThis Dashboard');
                        return;
                    }
                    
                    if ( $chronicle->get('grower_id') === $_SESSION['uid'] ) {
                        $placeholders['dashboard.subtitle'] = ': '.$chronicle->get('title');
                        $placeholders['chronicle.id.field'] = '<input type="hidden" name="chronicle_id" id="chronicle_id" value="'.$_GET['id'].'" />';
                        $placeholders['grow.id.field'] = '<input type="hidden" name="grow_id" id="grow_id" value="'.$_GET['gid'].'" />';
                        $placeholders['fi.leader'] = $chronicle->get('leader_url');
                        if ( $chronicle->get('day') ) { $placeholders['fi.day'] = $chronicle->get('day'); }
                        if ( $chronicle->get('week') ) { $placeholders['fi.week'] = $chronicle->get('week'); }
                        $placeholders['fi.summary'] = $chronicle->get('summary');
                        $placeholders['fi.content'] = $chronicle->get('content');
                        $placeholders['fi.tags'] = $chronicle->get('tags');
                        $placeholders['grow.id'] = $_GET['gid'];
                        $placeholders['formit.call']  = '[[!FormIt?'.
                                                            '&hooks=`saveChronicleProcessor,redirect`'.
                                                            '&redirectTo=`15`'.
                                                            '&redirectParams=`{"id":"'.$_GET['gid'].'"}`'.
                                                            '&validate=`day:required:isNumber,'.
                                                                'week:required:isNumber,'.
                                                                'summary:required:minLength=^50^,'.
                                                                'content:required,'.
                                                                'publish_on:isDate`'.
                                                        ']]';
                    
                        $var = $chronicle->get('publish_on');
                        $date = date('m/d/Y', strtotime($var));
                        
                        $placeholders['fi.publish.date'] = $date;
                        
                        if ( $chronicle->get('published') === 1 ) {
                            $placeholders['fi.published'] = 'checked';
                        } else {
                            $placeholders['fi.published'] = '';
                        }
                    
                    } else {
                        $url = $modx->makeUrl( 7 );
                        $modx->sendRedirect( $url );
                    }
                    
                    $modx->setPlaceholders( $placeholders );
                    
                    [ed. note: aaronkent last edited this post 9 years, 3 months ago.]
                      • 49407
                      • 159 Posts
                      As you can see I am going to try to output the FormIt call itself as a placeholder, to test if the grow ID will be set successfully.