2

Specifications:

  • I have a web-form that outputs the results as PHP variables.

  • Using RSForm Pro

  • Joomla! 2.5.14

  • Admin Email Output

Examples:

The 'modify the output layout':

To Approve this request, Please Add it to the Calendar:

http:///phpt/getform.php?name={Name:value}&dateFrom={from:value}&dateTo={until:value}

Output:

To Approve this request, Please Add it to the Calendar:

http:///phpt/getform.php?name=Josh Thomson&dateFrom=...etc

Problem:

The variables are output with spaces. As the variables are being attached to a URL, I was hoping to encode the variables with the correct encoding. e.g. %20 for 'spaces', so that eventually the output will look like so:

To Approve this request, Please Add it to the Calendar:

http:///phpt/getform.php?name=Josh%20Thomson&dateFrom=...etc

I am working with PHP ONLY, so please can you specify a solution that will take a variable and return an encoded variable... I assume it will look something similar like this:

$encodnameval = encodeurl($_POST['form']['name']);

Any help is greatly appreciated, Merci! Josh.

Edit: Code above changed, but still not working.

outputs to URL:

http:///phpt/getform.php?name=$encodnameval&dateFrom=...etc

Needs to work with RSForms.

josh.thomson
  • 905
  • 9
  • 25

4 Answers4

3
urlencode($string)

is exactly what youre looking for. http://de2.php.net/manual/en/function.urlencode.php

or just replace all spaces with %20 if thats the only char you need to replace

Merlin Denker
  • 1,380
  • 10
  • 15
  • I a building the function's behind the form, so It will be taking in hundred's (if not thousands) of multi-worded/symbol containing strings... So I do need this piece of code. ...I did figure out that it was only 1 parameter, but was accidently using JS code just now: 'encodeURI('$_POST["form"]["Name"]');' – josh.thomson Mar 04 '14 at 13:42
  • Well, remember that an URL has a maximum length. If it gets too long you will have to send the data with `GET` – Merlin Denker Mar 04 '14 at 13:43
  • it's fine, I just need to get it onto the URL somehow – josh.thomson Mar 04 '14 at 13:51
1

As Marlin said urlencode() will work for you..

use it as below..

let say you want to send this

 $name = 'Josh Thomson';  // $name = $_POST['form']['Name'];
 $url = 'http://phpt/getform.php?name='.$name;

what you need to do is..

$name = urlencode('Josh Thomson'); // $name = urlencode($_POST['form']['Name']);
$url = 'http://phpt/getform.php?name='.$name;

then the it will automatically become safe.. Like

http://phpt/getform.php?name=Josh%20Thomson

Feel free to ask any questions..

Haroon
  • 480
  • 4
  • 14
  • Can't do this method, you just turned it into a static input. It needs to be dynamic – josh.thomson Mar 04 '14 at 13:47
  • Needs to be something that modifies the $_POST['form']['Name'] variable – josh.thomson Mar 04 '14 at 13:47
  • Josh you can use `$name = urlencode($_POST['form']['Name']); $url = 'http:///phpt/getform.php?name='.$name;` You can do it like that.. – Haroon Mar 04 '14 at 14:30
  • isn't working, I have just thought of an idea, I will try embedding some PHP to hidden fields so that the input data is replicated into hidden fields as encoded versions, then to attach the encoded copies (hidden fields) to the URL... I appreciate everyone’s help so far! – josh.thomson Mar 04 '14 at 15:01
1

I found out that automatic encoding is done within the browser, so a static hyperlink of:

http://mywebsite.org/phpt/myscript.php?name={Name:value}&dateFrom={from:value}&dateTo={until:value}

is all was required for the link to produce a valid URL.

In rsforms this meant writing the HTML parts of the URL within the 'Source Editor' and the string elements within the Text Editor, and Whoila! it works!

http://amazewebs.com/demo = shows my script working with the POST method instead.

josh.thomson
  • 905
  • 9
  • 25
0

So this will work for you: $name = urlencode($_POST['name']); $encodnameval = 'Name: '.$name;

Theo
  • 150
  • 11
  • it needs to be placed within the dynamically created URL, and its a POST, not a GET – josh.thomson Mar 04 '14 at 13:48
  • Ok Josh I changed that part, so the code should be correct now. – Theo Mar 04 '14 at 14:07
  • This doesn't answer my question sorry. I am looking for a way of Outputing a URL to the administrator email, with encoded input variables. I am not looking for a way to simply encode variables. Thanks for your effort though.... The fix I am looking for will look a little more like so: ....EMAIL contained link: http:///phpt/getform.php?name=........ PHP Script within RSFORMS: $nameVar = urlencode($_POST["form"]["Name"]);$adminEmail[0] = $nameVar;........ However, it looks like the Initial PHP POST is not being POSTED on FORM submission – josh.thomson Mar 04 '14 at 14:14