We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 39437
    • 13 Posts
    Hi,
    I am trying to set an URL Parameter from a placeholder but I am stuck. This task is so easy that I think that it is possible but I am doing something wrong.
    Look at this, this is what I am trying:
    <a href="[[~[[*id]]? &tag=`[[!+text]]` ]]">[[~[[*id]] ]]?tag="[[!+text]]" )</a>


    The value of the Placeholder is placed inside the a-tag but the href looks like this:
    /?tag=%5B%5B%2Bform.text%3Aurlencode%5D%5D
    which translates into
    [[!+text]]


    Analyzing the problem I tried some Resource Tag like this:
    href="[[~[[*id]]? &tag=`[[*pagetitle]]` ]]"

    it works without any Problem.

    Does anybody know, is this my mistake or is there any other reason why this will not work?

    Meanwhile I will do it like that:
    href="[[~[[*id]]]]? tag=[[+form.text:urlencode]]"


    But is it necessary to do it like that?

    Regards, Hannes [ed. note: panther last edited this post 12 years ago.]
      MODX Rocks I am so glad that I have found it.
      • 3749
      • 24,544 Posts
      I think the exclamation point here may be causing your problem. It delays processing of the placeholder tag so the result is not available when the outer tag is processed.

      [[!+text]]

        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
        • 39437
        • 13 Posts
        Yes, you are right. It works if I skip the exclamation mark and have the Placehoder uncached:
        href="[[~[[*id]]? &tag=[[+form.text]] ]]"


        I have set up a test Template to analyze the effect:
        [[!setPlaceholders? &ph=`form.text==get.text !! "[[+get.tag]]"` ]]
        [[!setPlaceholders? &ph=`get.tag` &prefix=``]]
        
        <form name="Formular" action="[[~[[*id]]]]" method="get">
        	Test-Parameter: 
        	<input type="text" tabindex=2 name="text" value='[[+form.text:default=`über den Wölkchen!`:htmlentities]]' />
        	<input type="submit" name="OK" value="OK" tabindex="40" />
        </form>
        
        <p>
        	[[!+form.text:is=``:then=`Please enter Test-Parameter first!`:else=`
        		This works:   <a href="[[~[[*id]]]]?tag=[[!+form.text:urlencode]]">
        				&#x5b&#x5b~&#x5b&#x5b*id&#x5d&#x5d&#x5d&#x5d?tag=&#x5b&#x5b!+form.text:urlencode&#x5d&#x5d
        			</a><br />
        		This doesn't: <a href="[[~[[*id]]? &tag=[[!+form.text]] ]]">
        				&#x5b&#x5b~&#x5b&#x5b*id&#x5d&#x5d? &tag=&#x5b&#x5b!+form.text&#x5d&#x5d &#x5d&#x5d
        			</a>
        	`]]
        </p>
        
        [[!+get.tag:notempty=`
        	<div><h1>Result</h1>
        		<ul>
        			<li>get.tag: "<b>[[!+get.tag:htmlentities]]</b>"</li>
        		</ul>
        	</div>
        `]]
        


        But it was not enough to just skip the "!" at the Placehoder Call, I had to remove it from the [[setPlaceholders]] snippetcall too.

        On my testmachine Caching is disabled, and therefore it works as expected with or without "!" but I think this is a bug. If it can't be fixed, it should at least be mentioned in the documentation at some point. I think it is quite common task.
        Or maybe it is a Problem with setPlaceholder?
          MODX Rocks I am so glad that I have found it.
          • 3749
          • 24,544 Posts
          That is odd, though parsing can get a bit tricky when you use nested tags with output modifiers, especially when the tag is in a chunk.

          Maybe I'm misunderstanding what you're doing, but unless the content will be displayed in getResources, your method seems unnecessarily complex.

          Wouldn't something like this do it?

          <a href="[[~[[*id]]]]?tag=[[!GetFormText? &alt=`Please enter Test-Parameter first!`]]">


          /* GetFormText snippet */
          $alt = $modx->getOption('alt', $scriptProperties, 'Alt text not sent');
          return $modx->getOption('form.text', $_POST, $alt, true);
          


          FWIW, I would be inclined to do the validation with JavaScript and then display an alert and not submit the form when the field is empty.

            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
            • 39437
            • 13 Posts
            Hi Bob, thank ou for your reply, you are always there and helpful and I a year ago, I did not reply to say Thank You. Something I wanted to do today. The Problem is odd, true. I do not remember how I resolved it, but About the JavaScript Validation my opinion is: Yes I do JS validation for user Friendliness, but when the data is sent to the server, I still have to check if they are valid. Maybe someone tries to trick my input rules and submits without JS.
            Thank You for your active Part in the Forum!
              MODX Rocks I am so glad that I have found it.
              • 3749
              • 24,544 Posts
              I'm glad I could help. smiley
                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