We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10525
    • 247 Posts
    This should be a simple thing to do, but the modx docs, and other googled docs, don't actually make it clear how to do this.

    My Aim
    I have a page template for pages with big forms (eg contact forms).
    My forms are saved in chunks.
    I have a TV for this template to allow selection of the form chunk for each page.
    So the template will display the page content, and then the form from the chunk below that, like so:
    [[*content]]
    [[*page-form]]

    My Question
    How do I set up the TV to do this? What Input and Output Options should be set? Should Input Type be Text? Should Output Type be default/Text/String?
    Syntax is given as @CHUNK chunk_name. Is this entered into the page's TV textbox? Or should @CHUNK be entered into the TV settings somewhere?



    modx 2.3.5 (sorry, there's no category for this version yet)
      • 47401
      • 295 Posts
      so basically you need to be able to dynamically create forms and assign a form to a specific page, using the same template?
        • 10525
        • 247 Posts
        Not sure what you mean by 'dynamically', but I am using formit, so the whole form plus formit code goes into a chunk. I create a page(resource), assign it to the Form Page template, then from the TV on that page select the chunk containing the form I want to use.

        It's just to avoid spending time creating a template for every form page - although the cost of trying to do this probably outweighs that saving smiley
          • 30585
          • 833 Posts
          @Gav, you can use the Listbox (Single-Select) for this. Radio options would also work here.

          In the input option values field, separate your chunk names by double pipes: (option1==value1||option2==value2)
          Contact form chunk one==contactForm1||Contact form chunk two==contactForm2||Contact form chunk three==contactForm3
          

          Then change your template like this:
          [[*content]]
          [[$[[*page-form]]]]
          


          This should work.
            A MODx Fanatic
            • 10525
            • 247 Posts
            Thanks for that Treigh. I have used such a TV listbox before, but here I am aiming just to enter the chunk name into a page TV textbox. Using a listbox means I would have to update the TV every time I create a new form chunk, then go to the page and select that new chunk. Given that each chunk is only going to be used once, on one page, and selected by me, it's probably over-complicated for this purpose. The aim here is just to be able to re-use a template instead of having several very similar.
              • 4172
              • 5,888 Posts
              put all that chunks into one category.

              have a listbox-TV with input-option-values like:

              @CHUNK inputOptionsForms


              have in the chunk 'inputOptionsForms' (MIGX installed):

              --Bitte Block auswählen--||
              [[migxLoopCollection? &classname=`modChunk` &tpl=`@CODE:[[+name]]==[[$[[+name]]]]` &outputSeparator=`||` &where=`{"category":"7"}`]]




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

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 10525
                • 247 Posts
                Ok Bruno I see the value of this - auto-generating the list for the TV. I don't have MIGX installed but can try this.

                Going back to the MODx docs, can anyone understand what they are trying to say regarding @CHUNK and TV's?...

                https://rtfm.modx.com/revolution/2.x/making-sites-with-modx/customizing-content/template-variables/bindings

                https://rtfm.modx.com/revolution/2.x/making-sites-with-modx/customizing-content/template-variables/bindings/chunk-binding

                  • 4172
                  • 5,888 Posts
                  with a @CHUNK - binding in inputOptions, you can build the options with the (parsed) chunk-content.

                  This is, what I've done above.

                  You could have the same result with @EVAL or @SELECT - bindings,
                  but for easier reading and for reusability of the code, which builds the input-options, I've choosed the @CHUNK - binding.
                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 30585
                    • 833 Posts
                    I haven't tested this, but it should work.

                    If you altered the names of your chunks to include a number indicating the related resource id, you could then do this:
                    // in your [[*page-form]] TV's default value, enter:
                    [[$myFormChunk-[[*id]]]]
                    

                    If the id of your Contact us page was 9, you could put the contact form in a chunk named myFormChunk-9.
                    If the id of your Register page was 10, your registration form could be named myFormChunk-10. And so on.

                    For this to work, the chunk names should all have the same prefix, whatever they are. in the example, I'm using myFormChunk-. Yours could be different. The only changing part should be the number at the end, representing the related page id. [ed. note: treigh last edited this post 10 years, 11 months ago.]
                      A MODx Fanatic
                      • 42562
                      • 1,145 Posts
                      You mean, same prefix wink
                        TinymceWrapper: Complete back/frontend content solution.
                        Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
                        5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.