Connecting Tech Pros Worldwide Help | Site Map

$_GET won't read my hidden field

bass-man
Guest
 
Posts: n/a
#1: Jul 17 '05
I am trying to include a dynamically changeable file in my website with
PHP and Javascript so I am using a hidden field to hold the name of the
file I want to include, and I am using the$_GET function to read the
hidden field, but it says the field has no value even though I have a
default value in the field. So my question is how do I get PHP to read
the value of a hidden field?

Ken Robinson
Guest
 
Posts: n/a
#2: Jul 17 '05

re: $_GET won't read my hidden field



bass-man wrote:[color=blue]
> I am trying to include a dynamically changeable file in my website[/color]
with[color=blue]
> PHP and Javascript so I am using a hidden field to hold the name of[/color]
the[color=blue]
> file I want to include, and I am using the$_GET function to read the
> hidden field, but it says the field has no value even though I have a
> default value in the field. So my question is how do I get PHP to[/color]
read[color=blue]
> the value of a hidden field?[/color]

Can we see the code that is failing? Without it, we can't do much more
than guess...

Ken

bass-man
Guest
 
Posts: n/a
#3: Jul 17 '05

re: $_GET won't read my hidden field


Here's the code

//include the file
<?php include('calendar/' . $e); ?>

//hidden field
<input name="ev" type="hidden" id="ev" value="noE.htm">

//get the value
$e = $_GET['ev'];

and it shows the following eror:

Warning: main(calendar/): failed to open stream: No such file or
directory in /asdf/asdf/public_html/index.php on line 206

Warning: main(calendar/): failed to open stream: No such file or
directory in /asdf/asdf/public_html/index.php on line 206

Warning: main(): Failed opening 'calendar/' for inclusion
(include_path='.:/usr/lib/php:/usr/local/lib/php') in
/asdf/asdf/public_html/index.php on line 206

Ken Robinson
Guest
 
Posts: n/a
#4: Jul 17 '05

re: $_GET won't read my hidden field



bass-man wrote:[color=blue]
> Here's the code
>
> //include the file
> <?php include('calendar/' . $e); ?>
>
> //hidden field
> <input name="ev" type="hidden" id="ev" value="noE.htm">
>
> //get the value
> $e = $_GET['ev'];[/color]

Are these lines cut out of a larger program or do they exist exactly in
this order?

Remember, PHP is executes on the SERVER and Javascript on the client.
By the time Javascript sees the source, PHP is long gone.

For this to work, you need something like:
<?
$e = (isset($_GET['ev']))?$_GET['ev']:'noE.htm');
include ('calendar/' . $e);
//
// ...
//
echo '<form method="GET" action="' . $_SERVER['PHP_SELF'] . '">' .
"\n";
echo '<input name="ev" type="hidden" id="ev" value="noE.htm">'."\n";
//
// rest of form
//
echo '<input name="submit" value="Submit">'."\n";
echo '</form>'."\n";
?>

[color=blue]
>
> and it shows the following eror:
>
> Warning: main(calendar/): failed to open stream: No such file or
> directory in /asdf/asdf/public_html/index.php on line 206
>
> Warning: main(calendar/): failed to open stream: No such file or
> directory in /asdf/asdf/public_html/index.php on line 206
>
> Warning: main(): Failed opening 'calendar/' for inclusion
> (include_path='.:/usr/lib/php:/usr/local/lib/php') in
> /asdf/asdf/public_html/index.php on line 206[/color]

Those errors occur because the first time the program is executed, the
variable '$e' is NULL. The line:

$e = (isset($_GET['ev']))?$_GET['ev']:'noE.htm');

will initialize $e to "noE.htm" if the the form hasn'nt been submitted
yet.

Ken

bass-man
Guest
 
Posts: n/a
#5: Jul 17 '05

re: $_GET won't read my hidden field


They are cut from a larger program, the include is in a one cell and
not in a form, the hidden field is in a different cell in a form, and
the $_GET is at the top above every thing else. What I have is a
calendar, and I want to be able to click each day of the calendar and
in a different cell see the events of that day, without reloading the
page. On each of the days of the calendar I have javascript onClick
that changes the value of the 'ev' hidden field. If you can suggest a
fix or an alternative I would be much obliged. Thanks.

Kenneth Downs
Guest
 
Posts: n/a
#6: Jul 17 '05

re: $_GET won't read my hidden field


bass-man wrote:
[color=blue]
> I am trying to include a dynamically changeable file in my website with
> PHP and Javascript so I am using a hidden field to hold the name of the
> file I want to include, and I am using the$_GET function to read the
> hidden field, but it says the field has no value even though I have a
> default value in the field. So my question is how do I get PHP to read
> the value of a hidden field?[/color]

$_POST ?

Is your hidden field inside of a form? What is the method of the form?

Usually $_GET returns the parms that were put into the URL, like
http://www.example.com/myprog.php?pa...ue&parm2=value

$_POST returns the parms that were in a <form> element, because forms are
almost always submitted with a method of "post".


--
Kenneth Downs
Secure Data Software, Inc.
(Ken)nneth@(Sec)ure(Dat)a(.com)
bass-man
Guest
 
Posts: n/a
#7: Jul 17 '05

re: $_GET won't read my hidden field


Yes the field is in a form, and it is POST, I have tried using $_POST
and that doesn't work either. I've also tried using form method GET.

Brion Vibber
Guest
 
Posts: n/a
#8: Jul 17 '05

re: $_GET won't read my hidden field


bass-man wrote:[color=blue]
> //include the file
> <?php include('calendar/' . $e); ?>
>
> //hidden field
> <input name="ev" type="hidden" id="ev" value="noE.htm">[/color]

This is very insecure; an attacker could modify the form to read back
any file on your system readable by the web server.

If you include files based on client input, you really need to carefully
validate the value before using it.

-- brion vibber (brion @ pobox.com)
Closed Thread