We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 44891
    • 35 Posts
    I have a snippet which includes a form.

    echo '<form name="form" action="[~5~]"  method="get"><input type="text" name="q" />
    <input type="submit" name="Submit" value="Search" /></form>';


    In the content area of the following page (http://www.mysite.com/modx/index.php?id=5)
    I have, [[!GetArtist]]. That is the snippet's name.

    I've tried all possible combinations for the form action="[~5~]" parameter but I can't get this going.
    The problem is, after submitting, it loses the page id and always redirect to the home page regardless of the landing parameter. It should go to the page with the form which is:
    http://www.mysite.com/modx/index.php?id=5.

    Some examples, when I enter the name Rembrandt in the form, and the different action parameters I tried:

    action="[[~[[*id]]]]"
    redirects me to: http://www.mysite.com/modx/index.php?q=rembrandt&Submit=Search
    
    action="index.php?id=5"
    redirects me to: http://www.mysite.com/modx/index.php?q=rembrandt&Submit=Search
    
    action="[~5~]"
    redirects me to: http://mysite.com/modx/~5~?q=rembrandt&Submit=Search
    
    action="[[~[[*id]]]]"
    redirects me to: http://www.mysite.com/modx/index.php?q=rembrandt&Submit=Search


    All redirects are false and (of course) produce no results.

    What am I overlooking or doing wrong? Can somebody please can give me a hint or advice? Thanks in advance.

    Form example: [ed. note: strooman last edited this post 12 years, 10 months ago.]
      • 3749
      • 24,544 Posts
      If you're using Revolution, that tag should be:

      [[~5]]


      You're using an Evolution-style tag.

      To use the page ID, you might try this:

      [[!~[[*id]]]]


      That will delay the processing of the link tag, which may be being parsed before the page ID is available.

      Also, in your snippet, you should use this:

      $output =  '<form name="form" action="[[~5]]"  method="get"><input type="text" name="q" />
      <input type="submit" name="Submit" value="Search" /></form>';
      
      /* ... */
      
      return $output;
      



      One more thing, if you want to redirect to the current page, you can also do this in the snippet, which might be more reliable:

      $docId = $modx->resource->get('id');
      $url = $modx->makeUrl($docId, "", "", "full");
      
      $output =  '<form name="form" action="' . $url . '" method="get"><input type="text" name="q" />
      <input type="submit" name="Submit" value="Search" /></form>';



      [ed. note: BobRay last edited this post 12 years, 10 months ago.]
        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
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        I think you meant [[~5]] wink
          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
          • 3749
          • 24,544 Posts
          Right. I pasted strooman's code and forgot to fix that. wink
            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
            • 44891
            • 35 Posts
            Revolution 2.2.10
            Operating system Windows 8.1
            PHP version PHP Version 5.3.27

            Ok, let me try to visualize this with the risk of being to elaborate

            First
            This is my setup for the page index.php?id=5. The [[!GetArtist]] refers to the snippet.


            Second
            This is the basic setup for the snippet.


            Third
            This is just a basic part of the snippet code.


            Fourth
            When I view the page at http://www.bertverberne.com/modx/index.php?id=5 the output is just fine and correct


            Fifth
            But the redirect failse.


            Another thing I noticed. In my index.php?id=5 page there is the following code
            <html>
              <head>
              </head>
                <body>
                  <p>Enter a name</p>
                  [[!GetArtist]]
                </body>
            </html>

            but the basic html code
            <p>Enter a name</p>
            doesn't show up when i view the page.

            The problem however is that I get a wrong redirect in this part
            <form name="form" action="[[~5]]"

            Tried every possible combination and went through the examples above. Didn't work however.
            You can find a working example in just plain php outside Modx.
            http://www.bertverberne.com/art/demo/
            This is what I try to accomplish within Modx but I can't get it going. [ed. note: strooman last edited this post 12 years, 10 months ago.]
              • 4172
              • 5,888 Posts
              Did you try this?
              $docId = $modx->resource->get('id');
              $url = $modx->makeUrl($docId, "", "", "full");
               
              $output =  '
              <form name="form" action="' . $url . '" method="get">
              <input type="text" name="q" />
              <input type="submit" name="Submit" value="Search" /></form>';
              

              This one should work.

              If you want to set the landing-page by snippet-tag:

              $docId = $modx->getOption('landing',$scriptProperties,$modx->resource->get('id'));


              and call you snippet with:

              [[!yourSnippet? &landing=`5`]]


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

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 44891
                • 35 Posts
                $docId = $modx->resource->get('id');
                $url = $modx->makeUrl($docId, "", "", "full");
                  
                $output =  '
                <form name="form" action="' . $url . '" method="get">
                <input type="text" name="q" />
                <input type="submit" name="Submit" value="Search" /></form>';
                


                Yes, I tried that one but then I don't see the textbox appear. BobRay gave me that tip. I will try your other advice and report back.
                  • 4172
                  • 5,888 Posts
                  but with no result.

                  don't forget to return the output with

                  return $output;


                  at the end.
                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 44891
                    • 35 Posts
                    OK, at least I get this code correct back

                    <html>
                      <head>
                      </head>
                        <body>
                          <p>Enter a name</p>
                          [[!GetArtist]]
                        </body>
                    </html>

                    So that's one problem less.


                    But I still get the wrong redirect with this code:

                    $docId = $modx->resource->get('id');
                    $url = $modx->makeUrl($docId, "", "", "full");
                       
                    return $output =  '
                    <form name="form" action="' . $url . '" method="get">
                    <input type="text" name="q" />
                    <input type="submit" name="Submit" value="Search" /></form>';
                    


                    Same problem with this code:
                    $docId = $modx->getOption('landing',$scriptProperties,$modx->resource->get('id'));

                    [[!yourSnippet? &landing=`5`]]

                    The problem is, after submitting, it loses the page id and always redirect to the home page regardless of the landing parameter. It should go to the page with the form which is:
                    http://www.bertverberne.com/modx/index.php?id=5. [ed. note: strooman last edited this post 12 years, 10 months ago.]
                      • 4172
                      • 5,888 Posts
                      you should add

                      <base href="[[++site_url]]">


                      to your head in the template
                        -------------------------------

                        you can buy me a beer, if you like MIGX

                        http://webcmsolutions.de/migx.html

                        Thanks!