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.

2
  • Pas de quoi Josh on t'aime! Commented Mar 4, 2014 at 13:30
  • en anglais s'il vous plaît Commented Jul 11, 2014 at 14:53

4 Answers 4

3
urlencode($string)

is exactly what youre looking for. https://www.php.net/manual/en/function.urlencode.php

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

Sign up to request clarification or add additional context in comments.

3 Comments

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"]');'
Well, remember that an URL has a maximum length. If it gets too long you will have to send the data with GET
it's fine, I just need to get it onto the URL somehow
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..

4 Comments

Can't do this method, you just turned it into a static input. It needs to be dynamic
Needs to be something that modifies the $_POST['form']['Name'] variable
Josh you can use $name = urlencode($_POST['form']['Name']); $url = 'http:///phpt/getform.php?name='.$name; You can do it like that..
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!
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.

Comments

0

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

3 Comments

it needs to be placed within the dynamically created URL, and its a POST, not a GET
Ok Josh I changed that part, so the code should be correct now.
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=<?phpecho $nameVar;?>........ 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.