How to remove special characters in URL during Form Submission - php

I am trying to remove the special characters during form submission in PHP. Everytime I want to submit a data for example :
<form action="?" method="get">
<input type="text" name="str" value="I want to remove this" />
</form>
the output in the browser looks like this
http://localhost/?str=I+want+to+remove+this
Is there anyway that we can get rid of those "+" before submission or during submission?
My expected result is
http://localhost/?str=I want to remove this
Thanks for your help...

In the url you cannot have empty spaces, on the server side
str=I+want+to+remove+this
will be read as
str=I want to remove this
only. So i do not think you really need to worry about that encoding.

Related

Space added in a text field

I have a problem with an input type text.
The value of the field is affected by PHP, like this:
<input type="text" class="form-control" name="ClientName" id="ClientName" value="<?php echo strtoupper($Client['name']).' '.trim($Client['surname']); ?>" />
Each time i have a space added at the end of the string, so when i save datas in my db with htmlentities() function, i have for example:
NAME Surname
I tried a lot of things, i'm sure my data from PHP don't have a space at the end. When i save datas in db, i make a TRIM on this input.
I can't remove this space and i don't know where it comes from!!
Do you have any idea?
Thanks

American apostrophe clears form input

’ this kind of apostrophe ruins my input which is saved to database. I've tried
$GeneralChangeDescriptions[$ChampionNumber+1][$indexGeneral+1]=str_replace("’", "'",
$GeneralChangeDescriptions[$ChampionNumber+1][$indexGeneral+1]);
So changing ’ to ' with no results I still get empty field.
This value with apostrophe is shown just fine but after sending it with
<input type="hidden" name="GeneralChangeDescriptions" value="'.htmlspecialchars(json_encode($GeneralChangeDescriptions)).'">
it no longer is visible the whole input is blank is there any way to fix this?
Update:
After fiddling a bit with code I found out that json_encode completely wipes my input after sending are there any easy solutions?

using custom querystring paypal

I have integrated paypal in my application. Everything works good.
I have a minor issue, i want my custom field email as query string on success page to insert more data for that user.
My input coding is below:
<input id="custom" name="custom" class="form_textbox"/>
And my redirect is as below:
<input type="hidden" name="return" value="http://myweburl.com/ticket.php?tck=test#email.com">
But its not passing dynamically. I want to pass email entered in input "custom" to this query string. I know may be the solutions will be basic, but i tried everything, but couldn't make it work.
It may be that that certain characters need to be encoded for URLs. At a minimum, you should be encoding the ? question mark in your return value. It also may not be a bad idea to encode the slashes /.
For example, here are some characters that may need to be encoded in your example:
? = %3F
/ = %2F
You can take reference other encoded characters on Wikipedia, or try Googling.

Apostrophe in Textarea PHP

I have a textarea that is part of a form that submits to a PHP file.
The problem is that when an apostrophe (’) is entered into the textarea, the corresponding REQUEST variable in PHP turns up empty ($_REQUEST['description']). If there is no apostrophe, the $_REQUEST['description'] contains the textarea text as intended. Entering punctuation like single quotes and double quotes also works but an apostrophe does not. The same problem occurs for <input type="text"></input> as well. Is there any way to fix that?
Try this
HTML code
<form action="cible.php" method="POST">
Group name: <input type="text" name="user">
<input type="submit" value="Submit">
</form>
PHP :
<?php
$groupname = htmlspecialchars($_POST['user'], ENT_QUOTES);
echo $groupname;
?>
It's work fine for me
Do you have magic quote in your php config ? Try to disable it.

PHP: simple form encoding/decoding

Probably, this question has been asked before, though, I'll ask it again.
Currently, I'm facing a problem with form encoding. When posting my form, all spaces are replaced by the "+" character. I would like to replace this "+" character by a real space.
Does someone has a PHP solution for this?
Thanks in advance.
Cheers, Lennart
Can't reproduce
<form>
<input type=text name="a" value="text with spaces">
<input type=submit>
</form>
<?php if (isset($_GET['a'])) echo $_GET['a'] ?>
no spaces at all. What i m doing wrong?
This shouldn't happen if the browser behaves correctly. My assumption would be that a javascript is messing with your data. Replacing spaces with pluses is done when encoding urls, maybe that will help.
You can use firebug to check for any js interference.
I'm using AJAX (x = in this case JSON) for handling the form posts etc
Then let's see the code.
Possibly you're doing something like trying to form-encode your data manually before another component also form-encodes it. Replacing a space with + is quite standard and expected for form-encoding, but if you accidentally do it twice then you're going to be left with an encoded + at the end of it.
If you are using the JavaScript escape function: don't. (When you need to URL-encode a form value for inclusion in a parameter, the proper method is encodeURIComponent. escape is a fruity non-standard encoding of its own which you should almost never have any need to use.)

Categories