The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Properly Encoding URL that contain spaces
Hello
I'm trying to figure out a way to encode url's that contain spaces. Normally I'd manually type %20 as needed, however what I'm doing is part of a form that creates a thread. Allow me to explain. A user fills out a form with their country, the form is submitted and the variable is pulled for the country to show the flag. The code is something like this: Code:
[img]http://test.com/images/flags/{qo_01}.png[/img] If the country is more than one word then problems start to happen. The resulting output code is something like this. Code:
[img][url]http://test.com/images/flags/United[/url] States It should be: Code:
[img]http://test.com/images/flags/United%20States.png[/img] The variable {qo_01} needs to have any spaces substituted with the %20 characters. I know how to do this in php, but is there some inline <vb: xx> function that can help? I've thought about BBCode for it too, but haven't tried anything. Thanks in advance! Van |
#2
|
|||
|
|||
Suppose you have someting like this:
HTML Code:
<input type="text" id="countryname" /> <input type="submit" value="Submit" /> HTML Code:
<input type="submit" value="Submit" onclick="encode()" />
Code:
<script type="text/javascript"> <!-- function encode() { var counrtyname = fetch_object('countryname').value; countryname=PHP.urlencode(countryname); fetch_object('countryname').value=countryname; } //--> </script> |
#3
|
|||
|
|||
Hi nerbert
Thanks for the response. I was hoping I didn't have to modify any templates as this would affect future updates of the mod I need it for (https://vborg.vbsupport.ru/showthread.php?t=234385) I guess I just need to bite the bullet... thanks |
#4
|
|||
|
|||
There is a {vb:urlencode variable} that may do what you want.
|
#5
|
|||
|
|||
kh99
so VERY close! It's substituting spaces with "+" instead of %20 |
#6
|
|||
|
|||
Yeah, it calls urlencode() which connverts special characters to %XX except spaces, which get changed to + for some reason. Oh well...
|
#7
|
|||
|
|||
Try encodeURI() instead of PHP.urlencode().
http://www.w3schools.com/jsref/jsref_encodeuri.asp PHP.urlencode() is a vBulletin function and it seems to be the opposite of urldecode() in PHP. |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|