0

I've a very strange problem in my form and have no idea how to solve it. Tried a search but found nothing about it. I have a form which i receive the data with $get in a php page to process the data. Strangely, when i insert an @ in a field like the email for example, the @ is lost durring the process of sending data. I verified in the line before the redirection to the php page if the @ was there and it was, so i don't know this character is lost in the next step of the process.

Any hints?

The redirection comes from a javascript function that i call when i click the submit form:

window.location.href = 'index.php?pagina=candidaturasB&'+ qstringA;

the "qstringA" contains all the data of my form, and if in some input i put an @, if i do alert(qstringA) before de redirection line, the @ is there, after that, in the url, of the php page where i received the data there's no @.

ex: index.php?...&email="ren@something.com" appears on the url "index.php?...&email="rensomething.com".

Marijn
  • 10,367
  • 5
  • 59
  • 80
user1511579
  • 1,517
  • 6
  • 26
  • 42
  • 2
    Can you post your code ? – Loïc G. Aug 06 '12 at 10:30
  • stripping special characters? – amitchhajer Aug 06 '12 at 10:31
  • 1
    Sounds to me like you are using the email address as a *key*, not a *value* and PHP is eating the `@` and converting it to a `_` for compatibility with [`register_globals`](http://php.net/manual/en/security.globals.php). Setting aside for a minute the fact that this is a stupid and annoying "feature" of PHP, which still happens in 5.4 *despite* the fact `register_globals` itself has actually now been *removed* - I think what you need to do is make sure you are transmitting the value *as a value*, and pass it through [`urlencode()`](http://php.net/urlencode) for the redirect. – DaveRandom Aug 06 '12 at 10:35
  • I updated my initial post. DaveRandom, like a key? Can you be more specific? I'm just retrieving the data from inputs, nothing more. – user1511579 Aug 06 '12 at 10:45

1 Answers1

1

Use urlencode() for each form data :

eg :

$url = "index.php?pagina=candidaturasB";
$url .= "&email=".urlencode($_GET['email']);
$url .= "&data="urlencode($_GET['data']);

And pass the result string to window.location.href

Loïc G.
  • 3,087
  • 3
  • 24
  • 36
  • Loic i just use $_GET on the page where i receive the data, in the javascript function i mentioned i get the value of the input using: var email=document.getElementById("email").value; Sorry i forget to mention this before – user1511579 Aug 06 '12 at 11:57
  • 1
    Ok so your problem is a JS problem, not PHP. Take a look at http://stackoverflow.com/questions/332872/how-to-encode-a-url-in-javascript – Loïc G. Aug 06 '12 at 12:03