| re: php variable retrieval
"danny" <dthomas@planet-inc.net> wrote in
news:112srp3qmrh2tf4@corp.supernews.com:
[color=blue]
> Hi,
>
> I need some help regarding variable passing in php. I have a script
> which writes the current form text box values to an email script which
> works correctly. Should I use a variable which was created on the page
> within a javascript to leaves me with a blank value.
>
> As an example,
>
> $sf_Bizname = $HTTP_POST_VARS['BizName'] works when BizName is the
> "name" of the textbox. It doesn't when it is declared as var BizName =
> "MyBiz".[/color]
PHP is a server-side language, so it knows nothing of any JavaScript
that's taking place on the client-side unless you force it to. The best
you can do is to set the contents of a form input field via JavaScript,
like so:
<html>
<head>
<script language="Javascript">
function SetBiz(item){
var BizName = "MyBiz";
item.value = BizName;
}
</script>
</head>
<body>
<form method="post" action="test.php">
<input type="text" name="biznamefield" onClick="javascript:MyBiz(this);">
<input type="submit"></form>
</body>
Upon submitting this form, if the user had clicked inside the text box,
test.php would receive $_REQUEST[biznamefield] with a value of "MyBiz."
You can use JavaScript methods other than onClick to set the field
values, of course; you could stick an onLoad() in the body tag to call a
function that would populate as many fields as you like.
While I haven't tried, I don't believe this will work on hidden fields.
hth
--
Bulworth : PHP/MySQL/Unix | Email : str_rot13('f@fung.arg');
--------------------------|---------------------------------
<http://www.phplabs.com/> | PHP scripts, webmaster resources |