Chat on IRC |
php form data
Posted by metacalx [send private reply] at September 20, 2002, 01:20:19 PM
basic question sorry,
is there a way to make a php variable equal to the input of a HTML form field? like there is in javascript: var aVariable = document.formName.formFeildName.value; ? ... thanks for any help ... ?
Posted by unknown_lamer [send private reply] at September 20, 2002, 01:26:07 PM
$_POST['varname'] or $_GET['varname'], depending on whether you used POST or GET, will get you the value of the form value 'varname'.
Posted by metacalx [send private reply] at September 20, 2002, 11:48:17 PM
thanks, i'll go and try it now!
:-)
Posted by DragonWolf [send private reply] at September 21, 2002, 08:41:26 AM
I thought (I think with both POST AND GET) php automatically put the form fields into variables with the same name?
i.e. <input name="hello"> will be put in $hello
Posted by gian [send private reply] at September 21, 2002, 09:01:00 AM
That is dependant on the configuration of your PHP install. By default versions < 4.10 (IIRC) do what you said, whereas things after that do not.
Posted by unknown_lamer [send private reply] at September 21, 2002, 10:40:45 AM
You can configure it to do that, but then it makes your code less readable (e.g. if you use $hello, then someone else may wonder where $hello is coming from, whereas $_GET['hello'] tells them that you are getting the variable from GET form data). Also, I believe that it is less secure because you don't know where the variables are coming from. E.g. if you use POST for your form I think (I'm probably wrong) anyone can just override the variables by adding the ?foo=bar&... so that more variables will be sent with GET and override the POST variables. I'm probably backwards on that though.
Posted by gian [send private reply] at September 21, 2002, 04:17:17 PM
You are correct. It can mean that your internal variables can be altered (but not if you are a half sensible programmer).
Posted by mop [send private reply] at September 21, 2002, 05:04:14 PM
I did that a long time ago when my friend sent me a "friend test" thing. I looked at the form's name for the score, and just put ?score=123123 etc. Thanks for telling me about this, I have PHP 4.1.0 and was unaware of this change.
Posted by AnyoneEB [send private reply] at September 22, 2002, 08:55:41 AM
I was just reading the PHP manual so I know that the setting is Register_Globals in php.ini, if it's on you get $hello, if it's off you have to use $get['hello'].
I'm not sure, but I thought the change was at 4.2.0?
Posted by mop [send private reply] at September 22, 2002, 12:07:07 PM
I must of typed the version number in wrong then.
Posted by DragonWolf [send private reply] at September 24, 2002, 04:48:23 AM
I realise the fall backs perfectly well but it saves me having to get them all the time.
I am in the habit of using comments to explain where ALL my variables come from and what they are for anywayz.
Register as a new user | |||||||||||||