Hi there!
I'm not great at regex, but I understand the basics. I have used regex101.com to check that what I am doing is correct, and as far as I can tell it is. I cannot for the life of me get it to work though.
On each templated out page of the site there is a custom field called "process_flowchart". This is set as an editable region type="file" but, under certain circumstances, the correct thing for a site editor to do is instead link directly to either a .pdf or to a different page of the website altogether (the latter being a new requirement!).
I got the .pdf part of this to work, using regex, some time ago:
This simply opens up the .pdf file in the browser window - nice and easy!
I am now trying to sort out the 'redirect to a different page of the website' and wanted the regex to be fairly strict (i.e. not possible to link people to external sites). Here is what I tried:
As far as I can tell, and checking with regex101 seems to confirm this, this regex should match any string which contains "handbook" followed by any other characters, but ending with ".php?p=" followed by one or more digits. This would mean that the only URLs that would work would be ones along the lines of "http://handbook/trade-marks-eu.php?p=96" I checked again, and regex101 says that this URL would match the above regex test (you can see my regex101 testing here: https://regex101.com/r/dqFt8M/1)
And yet it doesn't work. Now, at first I was worried that this was because unlike the .html and .pdf situations, this one is not a 'file' so maybe something inside Couch was saying "nope - not a 'type=file' so I will not output this!", so I did a cms:dump_all to double check and it shows:
to my mind, this should mean that the <cms:validate /> should work, as should the redirect, but it does not and it instead shows the error message that I set under a <cms:else />
I'm not great at regex, but I understand the basics. I have used regex101.com to check that what I am doing is correct, and as far as I can tell it is. I cannot for the life of me get it to work though.
On each templated out page of the site there is a custom field called "process_flowchart". This is set as an editable region type="file" but, under certain circumstances, the correct thing for a site editor to do is instead link directly to either a .pdf or to a different page of the website altogether (the latter being a new requirement!).
I got the .pdf part of this to work, using regex, some time ago:
- Code: Select all
<cms:if "<cms:validate value=process_flowchart validator='regex=/pdf$/' />" >
<cms:redirect url="<cms:show process_flowchart />#toolbar=0" />
<cms:else />
This simply opens up the .pdf file in the browser window - nice and easy!
I am now trying to sort out the 'redirect to a different page of the website' and wanted the regex to be fairly strict (i.e. not possible to link people to external sites). Here is what I tried:
- Code: Select all
<cms:if "<cms:validate value=process_flowchart validator='regex=/((handbook.+)(\.php\?p\=)\d+$)/' />" >
<cms:redirect url="<cms:show process_flowchart />" />
<cms:else />
As far as I can tell, and checking with regex101 seems to confirm this, this regex should match any string which contains "handbook" followed by any other characters, but ending with ".php?p=" followed by one or more digits. This would mean that the only URLs that would work would be ones along the lines of "http://handbook/trade-marks-eu.php?p=96" I checked again, and regex101 says that this URL would match the above regex test (you can see my regex101 testing here: https://regex101.com/r/dqFt8M/1)
And yet it doesn't work. Now, at first I was worried that this was because unlike the .html and .pdf situations, this one is not a 'file' so maybe something inside Couch was saying "nope - not a 'type=file' so I will not output this!", so I did a cms:dump_all to double check and it shows:
- Code: Select all
process_flowchart: http://handbook/trade-marks-eu.php?p=96
to my mind, this should mean that the <cms:validate /> should work, as should the redirect, but it does not and it instead shows the error message that I set under a <cms:else />