Search code examples
phphtmlurlencodeasciiencoding

Encoding a PHP variable to URL link


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.


Solution

  • 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.