You don't need to to anything. Send it as is. Browser and PHP will do all escaping and unescaping for you (if you use form.surl.value = surl; form.submit()
and $_POST['surl']
). Or you can just use the plain form without any JavaScript (if it fulfills your needs).
Replying henasraf's comment. Try this.
<form id="form" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"
onsubmit="this.via_js.value=this.via_plain_form.value;">
<input type="hidden" name="via_js"/>
<input type="text" name="via_plain_form" value="Paste you url here"/>
<input type="submit" name="submit" value="Submit"/>
</form>
<?php
if (isset($_POST['submit'])) {
var_export($_POST);
}
?>
For http://www.google.co.in/search?q=javascript+urlencode+w3schools
, it outputs
array (
'via_js' => 'http://www.google.co.in/search?q=javascript+urlencode+w3schools',
'via_plain_form' => 'http://www.google.co.in/search?q=javascript+urlencode+w3schools',
'submit' => 'Submit',
)