0

I am trying to see if URL encoding of GET parameters while submitting a form is possible. I have seen a few resources where URL encoding is being is used where the URLs are built dynamically

Example: www.google.com?query=urlencode($query)

But how do I apply the function urlencode() if I am using a form and a submit button?

<html>
    <body>
        <form action="send.php" method="get">
            <input type="input" name="method" value="" />
            <input type="submit" name="submit" value="submit"/>
        </form>
    </body>
</html>
2
  • if i don't misunderstood your question, why you don't use urlencode() ? Commented Jan 26, 2011 at 16:22
  • In your comments below you never test with characters that actually get encoded, e.g. spaces. Try it. "application/x-www-form-urlencoded" is the default encoding. You can't expect an encoding of the whole query part (starting with "?"), just the individual parts values. And note there are subtle (historical) differencies between urlencode and rawurlencode. Commented Jan 26, 2011 at 16:44

2 Answers 2

3

The browser will urlencode them for you. Go to google and search for "&", and you'll see "q=%26" in the URL.

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

1 Comment

hey but I still am able to see what I have passed as parameters. Nothing has changed. localhost/test.php?opt1=check_test&subt=subt, is what I get when I submit
2

This is done by the browser if you ask it to do it. Consider using enctype="application/x-www-form-urlencoded":

<html>
    <body>
        <form action="send.php" method="get" enctype="application/x-www-form-urlencoded">
            <input type="input" name="method" value="" />
            <input type="submit" name="submit" value="submit"/>
        </form>
    </body>
</html>

Note that it is done by default in most modern browsers if you don't even specify enctype.

2 Comments

hey but I still am able to see what I have passed as parameters. Nothing has changed. localhost/test.php?opt1=check_test&subt=subt, is what I get when I submit
Of course you wont see that for what you have entered, you will see for special characters like &, #, / and so on, the other characters are not changed at all

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.