We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8898
    • 181 Posts
    Hi,

    are there any restrictions regarding the generation of URLs with link tags where the ID is provided by a placeholder? I used this construct quite often, but now it lets me down...

    I have a page (resource) that includes a form defined in a chunk:

    [[$DirectApplicationForm? &jobResId=`[[!getReqParam? &name=`position` &type=`GET`]]` ]]

    "position" is a GET parameter holding a resource ID.

    The chunk looks like this (it uses FormIt / FormitFastPack):

    [[!FormIt?
        &hooks=`spam,fiProcessArrays,fiGenerateReport,email,redirect`
        &errTpl=`<p class="ym-message">[[+error]]</p>`
        &validationErrorMessage=`<p class="errorMessageBox">Es ist ein Fehler aufgetreten. Bitte überprüfen Sie die Werte, die Sie in das Formular eingegeben haben.</p>`
        &emailTpl=`DirectApplicationEmailTpl`
        &emailTo=`[[++emailsender]]`
        &redirectTo=`[[++cfg.directApplicationFormRedirectId]]`
        &emailFrom=`[email protected]`
        &emailFromName=`MODX Revolution CMS`
        &emailToName=`My customer's company name`
        &emailSubject=`Website-Formular: Direkt bewerben`
        &emailHtml=`0`
        &store=`1`
        &storeTime=`180`
        &validate=`aspiredPosition,
            appellation:required,
            title,
            firstName:required,
            surname:required,
            street,
            addressAddition,
            zipCode,
            city,
            country,
            phone:required,
            email:required:email,
            comments,
            priority,
            attachment,
            confirmation:required`
        &submitVar=`submitForm`
        &figrTpl=`formReportRow`
    ]]
    
    <form action="[[~[[*id]]]]" method="post" enctype="multipart/form-data" id="directApplicationForm" class="ym-form ym-columnar">
        [[!fieldSetDefaults?
            &outer_class=`ym-fbox-`
            &error_class=`ym-error`
        ]]
    
    [[!+fi.validation_error_message]]
    <p>Die durch einen Stern (<span class="requiredFieldIndicator">*</span>) gekennzeichneten Felder sind Pflichtfelder und müssen von Ihnen ausgefüllt werden.</p>
    [[!+fi.error.error_message:notempty=`<p>[[!+fi.error.error_message]]</p>`]]
    
        <fieldset>
            [[!field?
                &type=`hidden`
                &outer_tpl=``
                &name=`nospam:blank`
            ]]
            [[!field?
                &type=`text`
                &name=`aspiredPosition`
                &label=`Gewünschte Position`
                &default=`[[!getResourceField?
                    &id=`[[+position]]`
                    &field=`JobName`
                    &isTV=`1`
                    &default=``
                ]]`
            ]]
            [[!field?
                &type=`hidden`
                &name=`positionUrl`
                &default=`[[++site_url]] - [[+jobResId]] - [[~24]] - [[~[[!+jobResId]]]]`
            ]]
    
    [...]
    
            [[!field?
                &type=`text`
                &name=`firstName`
                &label=`Vorname`
                &required=`1`
            ]]
            [[!field?
                &type=`text`
                &name=`surname`
                &label=`Nachname`
                &required=`1`
            ]]
        </fieldset>
    
    [...]
    
        <fieldset>
            [[!field? &type=`submit` &name=`submitForm` &label=`noLabel` &value=`Jetzt absenden` &class=`ym-button ym-save`]]
        </fieldset>
    </form>

    I left some parts of the form out; they shouldn't make a difference.

    The interesting part is the hidden field named positionUrl. The notation

    &default=`[[++site_url]] - [[+jobResId]] - [[~24]] - [[~[[!+jobResId]]]]`

    has been chosen purpously (for testing). The site URL is generated correctly, so is the ID represented by the placeholder jobResId and the path to the resource with the ID 24. [[~[[!+jobResId]]]] instead leads to an empty string, with or without the exclamation mark:

    <input type="hidden" name="positionUrl" value="http://mycustomersdomain.tld/ - 24 - jobs/teamleiter-vertriebsinnendienst-m-w.html -  " />

    Okay, I tried to generate the part of the URL in the resource and bring it into the chunk via an additional placeholder:

    [[$DirectApplicationForm?
        &jobResId=`[[!getReqParam? &name=`position` &type=`GET`]]`
        &jobResUrl=`[[~[[!getReqParam? &name=`position` &type=`GET`]]]]`
    ]]

    But

    &default=`[[++site_url]][[+jobResUrl]]`

    doesn't work either...

    Maybe I'm just too tired by now, but I don't understand why this leads to an empty string. I'd appreciate it very much if someone could push me in the right direction!

    Cheers,
    Jan
      This message has been ROT-13 encrypted twice for higher security.
      • 8898
      • 181 Posts
      Okay, after having some sleep I worked around this by using getReqParam directly in the chunk and by generating the URL with a small snippet. Nevertheless I'd really like to understand why this construct doesn't work...

      Cheers,
      Jan
        This message has been ROT-13 encrypted twice for higher security.
        • 22303 MODX Staff
        • 10,725 Posts
        It should work, so long as the placeholders are not in a property set or the default properties of the Snippet. If they are, then you need to pre-process those properties by checking the checkbox which specifies you should pre-process property sets.

        Also, make sure you are not running 2.2.7 if the links are coming from other contexts. There was a bug with cross-context linking in that release which was resolved in 2.2.8.
          • 8898
          • 181 Posts
          Hi Jason,

          thank you very much for your reply.

          Quote from: opengeek at Jun 27, 2013, 07:40 AM
          It should work
          That's what I thought, too... wink

          Quote from: opengeek at Jun 27, 2013, 07:40 AM
          so long as the placeholders are not in a property set or the default properties of the Snippet.
          No, there are no properties involved. As I said, the placeholder jobResId is set in the resource and handed over to a chunk, where I try to use [[~[[+jobResId]]]], which doesn't work although [[+jobResId]] holds the correct value (the ID of the resource I want to link to).

          Quote from: opengeek at Jun 27, 2013, 07:40 AM
          Also, make sure you are not running 2.2.7 if the links are coming from other contexts. There was a bug with cross-context linking in that release which was resolved in 2.2.8.
          I'm using version 2.2.8 (updated from 2.2.7 as soon as 2.2.8 was released). Apart from that, it all happens within the "web" context.

          Any other ideas? I'm really baffled...

          Cheers,
          Jan
            This message has been ROT-13 encrypted twice for higher security.
            • 22303 MODX Staff
            • 10,725 Posts
            Does it work if you make the link tags themselves non-cacheable? The problem is likely that you are processing the Chunk on the first cacheable pass, but the non-cacheable getReqParam calls are delayed while the link tags are not, so the links are attempting to use the unprocessed tags as the link value.

            e.g.

            [[!~[[+jobResId]]]]
              • 8898
              • 181 Posts
              Hello Jason,

              I'm very sorry for answering so late - I didn't get a notification e-mail, and then I've been on holiday, so I've just seen your reply by chance...

              Quote from: opengeek at Jun 27, 2013, 04:45 PM
              Does it work if you make the link tags themselves non-cacheable? [...]

              e.g.

              [[!~[[+jobResId]]]]
              I just tried this (even with [[!~[[!+jobResId]]]]), but it doesn't work.

              Well, my current solution works fine, so there's no real problem anymore, I just hate it when things go wrong and I don't know why... wink

              Cheers,
              Jan
                This message has been ROT-13 encrypted twice for higher security.