⚠️ Urgent! Active Attacks on MODX Revolution Sites Below Revolution 2.6.5
Subscribe: RSS
  • Hi all,

    I refer to the article Named Anchor in the Revo Documentation.

    Adding the Resource ID like in this example
    <a href="[[~[[*id]]]]#prohibited">Prohibited Activities</a>

    will reload the page. As far as I see, the plugin solution will reload it likewise.

    The problem is that there is a form on that same page, and its fields will loose their values (becoming their defaults again).

    What can I do? Some Ajax stuff?

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

    • The problem is that MODX is based on the index.php file, all other URLs are rewritten to go to the index.php file by the web server. So a #goto link by itself will load the home page.

      If you are using FormIt, the &store property along with the FormitRetriever snippet should solve your problem.
      http://rtfm.modx.com/extras/revo/formit/formit.formitretriever
        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
      • Quote from: ottogal at Aug 01, 2014, 12:17 PM
        Hi all,

        I refer to the article Named Anchor in the Revo Documentation.

        Adding the Resource ID like in this example
        <a href="[[~[[*id]]]]#prohibited">Prohibited Activities</a>

        will reload the page. As far as I see, the plugin solution will reload it likewise.

        The problem is that there is a form on that same page, and its fields will loose their values (becoming their defaults again).

        What can I do? Some Ajax stuff?

        Are you using < base href > in your headers? If not, just make the link < a href="#prohibited" >Prohibited Activities< /a > and it will work. If you ARE using base href, do you really need to?
        • One method (if you are not using FormIt), is to have placeholders for the field values in the Tpl chunk.

          The snippet that processes the form can set those placeholders from the $_POST data if it's a reload. Be careful to sanitize the $_POST data first, though.
            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
          • Thank you all for your hints.

            I use <base href="[[++site_url]]"/> in all my headers, like many times recommended as best practice.

            MODX is based on the index.php file, all other URLs are rewritten to go to the index.php file by the web server.
            What I don't understand: Why [[~7]] is not rewritten to inx.php?id=7 (or, having FURLs enabled, to alias-of-id7.html)?

            My Form is very simple, just for entering options for sorting and filtering the output of a custom table. So there is no need for sanitizing the input values. For that reason I think FormIt would be too big a tool (the Germans would say "It's shooting with canons on a sparrow").

            And it uses the get method; on submit the page is reloaded, the field values of the form being set again by snippets which fetch the values from the $_GET array. Works fine.

            So I would like to keep get (instead of using post). Wouldn't it be possible to achieve the refilling of the form fields on <a href="[[~[[*id]]]]#anchor"> in the same way as on the submit of the form?
            • If you have friendly URLs enabled, [[~7]] will generate a URL of alias.html (depending on how you have your MODX installation configured), which the web server, if it has mod_rewrite or its equivalent enabled, will rewrite to "index.php?q=alias.html". With the Apache web server, this is usually done in the .htaccess file. It can, however, be done in the httpd.conf instead. Some web servers, like nginx, must have rewrite rules in its configuration files.

              If you do not have friendly URLs enabled, you'll just get index.php?id=7 and no need for rewrites. [ed. note: sottwell last edited this post 4 years, 4 months ago.]
                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
              • discuss.answer
                Now I made a workaround avoiding anchors at all.

                My page has a list in the <main> part and the form in the <aside> part.
                On a mobile device, the parts are linearized, <main> followed by <aside>, and my aim was to enable the visitor of the page to jump down to the form.

                Because I want to stay with the get method for processing the form, at the top of <main> I inserted a button which on click will hide the <main> part. Submitting the form will reload the page (getting the values back from $_GET) and automatically show the <main> again. [ed. note: ottogal last edited this post 4 years, 4 months ago.]
                • Very nice! May I use this in the Cookbook?
                    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
                  • Thank you, Susan!
                    You may use it, of course - I'd feel honoured...
                    • Would you mind posting the actual Javascript you use to accomplish this?
                        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