Omzy Posted August 10, 2009 Share Posted August 10, 2009 I POST the following as a hidden variable in my first form: echo '<input type="hidden" name="username" value="'.htmlentities($_POST['username']).'"/>'; This takes you to the second form, which has the following: echo '<input type="hidden" name="username" value="'.$_POST['username'].'"/>'; I assume it would carry forward the exact value that has been POSTed. I tested this using a string with an 'ampersand' (&) and in the first form it works as expected, by converting '&' into '&'. However in my second form it seems to convert it back to '&'. Is this the default behaviour/do I have to re-convert it using htmlentities() in my second form, or have I missed something out? Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted August 10, 2009 Share Posted August 10, 2009 It doesn't change the value, it returns a new value. Few of the functions have what you call a side effect. Edit: I misread your topic, but you still have to do it each time. It doesn't mean that the value will be &, but it has to be like that in the HTML source in order to be valid. The posted value will still be &. Quote Link to comment Share on other sites More sharing options...
Omzy Posted August 10, 2009 Author Share Posted August 10, 2009 But that's what I don't understand - in the source the value is "&" - that is the posted value, i.e whatever is in the source should be passed forward, not what gets displayed on screen! Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted August 10, 2009 Share Posted August 10, 2009 No. & represents the character &. It has to be escaped in the HTML source because you can't just have an ampersand. That character has a special meaning in itself. Same with other characters like "greater than" or "lower than" and other characters. Quote Link to comment Share on other sites More sharing options...
Omzy Posted August 10, 2009 Author Share Posted August 10, 2009 Yeah I understand that, but what I'm saying is why does PHP need to convert it back to '&' - why can't it just leave it as it is! Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted August 10, 2009 Share Posted August 10, 2009 It doesn't convert anything back. It IS an ampersand. & in the source means & in "reality" -- whether you post it or display it on the screen. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.