Jump to content

URL encoding when submitting a form?


darkminos

Recommended Posts

Sooo... every time I try to submit a form, the url is being encoded

 

.php?res_per_page=25&sort_by=Relevance&search_items%3Dsomething%26search_dropdown%3DAll=

 

echo   	 "<form method=get";
echo   	 "?";
echo 		 ">";
echo   	 "Display items";
echo    	 "<select name=res_per_page>";
...
echo		"</select>";
echo		"Sort by";
echo		"<select name=sort_by>";
...		
echo		"		</select>";
echo		"		<input type=hidden name=$replaced>";
echo		"		<input type=submit value=GO class=searchbutton>";
echo		"		</form>";

 

Even when trying to decode it before submitting with the following code...

 

    $entities = array('%21', '%2A', '%27', '%28', '%29', '%3B',
     '%3A', '%40', '%26', '%3D', '%2B', '%24', '%2C', '%2F', '%3F', '%25', '%23', '%5B', '%5D');
    $replacements = array('!', '*', "'", "(", ")", ";", ":", "@",
     "&", "=", "+", "$", ",", "/", "?", "%", "#", "[", "]");
    $replaced = str_replace($entities, $replacements, $temp);

Link to comment
Share on other sites

I mean, is there a way for the browser to show = rather than %3D?? there is too much happening within the script for me to change all of the variables to urlencode()

 

There's a reason it's encoded... you don't want to change this behaviour.

Link to comment
Share on other sites

Certain characters have special meaning in the URL, so the browser must encode them before sending them. PHP realizes this, and will (should) decode them before you see them in $_GET.

 

Are you seeing a problem processing this data in your PHP script? If so, describe the problem you are having and we can probably help.

 

Are you just looking for a way to make the url look "pretty"? If so, you need to look into the (Apache) mod_rewrite module.

 

 

Link to comment
Share on other sites

Right, sorry I should have explained better. Looks have nothing to do with my problem. the last time I done php is 10 years ago and see some differences, like the variable carried over in the URL is not always accessible by just calling it $some_variable, now I have to $_GET['some_variable']... not always however. Now, when I have some_variable=something in the URL I can get it no problem with $some_variable, however when I have some_variable%3Dsomething I can't get it. I hope this makes sense.

 

Link to comment
Share on other sites

I've never had PHP automatically urlencode() values for me.

 

You have whenever you submitted a form with method = GET, but not when you build a querystring yourself

 

I'm not sure what you mean? Isn't submitting a form a client-side action? GET/POST is decided and implemented client-side?

Link to comment
Share on other sites

Ok... I can't believe how simple the solution was...

 

echo  "<input type=hidden name=search value=".$_GET['search'].">";

 

I was trying to send the actual variable in the name field...

 

It was good to be educated on some of the changes done since PHP3

 

Thank you for the help!

Link to comment
Share on other sites

@xyph

 

<?php
echo <<< html
    <form method='get'>
        <input type='text' name='text1' value='a b c' />
        <br /><br />
        <input type='submit' value='Submit' name='btnSub' />       
    </form>
html;
?>

 

What I meant was this.

 

When the above form  is submitted, the query string will be

?text1=a+b+c&btnSub=Submit

 

ie the text field value is automatically urlencoded.

Link to comment
Share on other sites

@xyph

 

<?php
echo <<< html
    <form method='get'>
        <input type='text' name='text1' value='a b c' />
        <br /><br />
        <input type='submit' value='Submit' name='btnSub' />       
    </form>
html;
?>

 

What I meant was this.

 

When the above form  is submitted, the query string will be

?text1=a+b+c&btnSub=Submit

 

ie the text field value is automatically urlencoded.

 

The encoding is done client-side though, right?

 

I still have no idea what the OP is really trying to accomplish, so maybe that's why I'm confused.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.