Connecting Tech Pros Worldwide Forums | Help | Site Map

php variable retrieval

danny
Guest
 
Posts: n/a
#1: Jul 17 '05
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".

TIA
danny



Daniel Tryba
Guest
 
Posts: n/a
#2: Jul 17 '05

re: php variable retrieval


danny <dthomas@planet-inc.net> wrote:[color=blue]
> 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]

Maybe you should post a complete, small, to the point example!

Senator Jay Billington Bulworth
Guest
 
Posts: n/a
#3: Jul 17 '05

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
Erwin Moller
Guest
 
Posts: n/a
#4: Jul 17 '05

re: php variable retrieval


danny wrote:
[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".
>
> TIA
> danny[/color]

Your JS must contain some mistake.
PHP is only receiving the form.

Try this to examine the posting:

<pre>
<?php
var_dump($_POST);
?>
</pre>

If you use in your form-action METHOD="GET" then replace the $_POST by
$_GET.


Regards,
Erwin Moller
danny
Guest
 
Posts: n/a
#5: Jul 17 '05

re: php variable retrieval


Thanks All,

I think during my frustration I didn't change the GET back to a POST while
trying to use a type="hidden". It now works correctly.
"Erwin Moller"
<since_humans_read_this_I_am_spammed_too_much@spam yourself.com> wrote in
message news:422ed8c4$0$28988$e4fe514c@news.xs4all.nl...[color=blue]
> danny wrote:
>[color=green]
> > Hi,
> >
> > I need some help regarding variable passing in php. I have a script[/color][/color]
which[color=blue][color=green]
> > 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[/color][/color]
a[color=blue][color=green]
> > javascript to leaves me with a blank value.
> >
> > As an example,
> >
> > $sf_Bizname = $HTTP_POST_VARS['BizName'] works when BizName is the[/color][/color]
"name"[color=blue][color=green]
> > of the textbox. It doesn't when it is declared as var BizName = "MyBiz".
> >
> > TIA
> > danny[/color]
>
> Your JS must contain some mistake.
> PHP is only receiving the form.
>
> Try this to examine the posting:
>
> <pre>
> <?php
> var_dump($_POST);
> ?>
> </pre>
>
> If you use in your form-action METHOD="GET" then replace the $_POST by
> $_GET.
>
>
> Regards,
> Erwin Moller[/color]


Closed Thread