Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

set variable from html form 2

Status
Not open for further replies.

cs12xge

Programmer
Dec 3, 2000
8
US
Hi Everybody,
I have another question:

I have a .php file that was called from an HTML form

<form action=&quot;searcheng.php&quot; method=&quot;post&quot;>

<input type=&quot;text&quot; id=&quot;searchText&quot;...>

if in the beginning of my .php file has a variable called $str,

How can I get the value inside the text field to be passed into the .php file into the varible $str?

I really hope there is a way to do it as my program depends on that.

thanks a ton!!

Henry

 
In your <input> tag, place a &quot;name=&quot; attribute. That value can then be referenced via $name or $HTTP_POST_VARS[&quot;name&quot;] (doing it the latter way has a slight benefit in that $name could be overridden with a GET variable, perhaps bypassing any javascript checking ... of course, you should check out the variable for corrupt data regardless). Upon doing that, you can simply insert a &quot;$str = $HTTP_POST_VARS[&quot;name&quot;]&quot; and you're off.

Take care,

brendanc@icehouse.net
 
Thanks Sophisticate,
Just one question...

Say I have something like this:

<form action=&quot;searcheng.php&quot; method=&quot;post&quot;>
<input type=&quot;text&quot; name=&quot;searchText&quot; ...>

<input type=&quot;submit name=&quot;submitButton&quot; value=&quot;find&quot;..>

</form>

isn't there something I have to set so that when I say
$str = HTTP_POST_VARS[&quot;name&quot;];

that it knows to get the value out of &quot;searchText&quot;
and not &quot;submitButton&quot;?

cause I just tried it and it returned an empty string.

thanks for the reply!!

Henry
 
Well you don't need to really, it'll be automatically created as [tt]$searchTest[/tt]. But if you want, in your case, you could set

[tt]$str=$HTTP_POST_VARS[&quot;searchText&quot;];[/tt]

 
Sorry 'bout that. Should have put in that last message that every instance of &quot;name&quot; refers to the name you give the input tag.. so if you have <input type='hidden' name='something' value='somethingelse'>, $name would actually be $something and $HTTP_POST_VARS[&quot;name&quot;] would be $HTTP_POST_VARS[&quot;something&quot;].

Take care,

brendanc@icehouse.net
 
Hey Inssider and sophisticate,
thanks a ton for both of your help, I have just botten a quantum leap on my program

Henry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top