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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Feeling like a newbie - my forms are broken

Status
Not open for further replies.

Terwin

Programmer
May 23, 2002
51
US
I have a small form (code snippet below) which allows the user to select the type of schedule they would like to display, the selection made via radio buttons. The form script calls itself upon submission, but the name/value attributes do not seem to pass themselves properly into variables. When I use HTTP_POST_VARS to check the value of "disp," the variable appears. The if statement below (if ($disp == 1)) doesn't work properly, however. In the section of code below the if statement is only used to mark the selected button as "checked." I realize that there are easier ways to handle checking the right button, but I will need the $disp value for the more important purpose of passing to my class functions to output the appropriate display. Am I missing something somewhere?

Thanks in advance,
Terwin

Code:
<?php
include('teachersched.php');

$sched = new TeacherSched;
$sched->CreateSched($sched);
?>
<table width=650 align=center border=1 cellpadding=1 cellspacing=1>
	<tr>
		<td bgcolor=#cccccc>
		<center><font size=3 face=arial, helvetica>Teaching Schedule</font></center>
		<br>
		<form method=post action=&quot;<?php
		echo $HTTP_SERVER_VARS[&quot;PHP_SELF&quot;];   
		?>&quot;>
		<font size=2 face=arial, helvetica>Show schedule for:</font>
		<input type=radio name=disp value=1 
		<?php 
			if ($disp == 1)
			{
				echo &quot;checked&quot;;
			}
 
where $disp come from ? database or from a Post?

The code you show us don't tell us anything.
If it came from database, you must read it, if it cames from a post, you should replace it for $_POST['disp'] (>=V4.1.0) or $HTTP_POST_VARS['disp'] (<V4.1.0) Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Sorry for being unclear...

It comes from the post.. I realize I only showed a piece of the form, but the &quot;disp&quot; comes from:

<input type=radio name=disp value=1>

So presumably when $PHP_SELF is called, it should generate a variable with the name $disp and a value of 1. HTTP_POST_VARS does seem to indicate that the variable exists, but the if ($disp == 1) statement does not execute properly by adding &quot;checked&quot; to the appropriate radio input line.

Thanks,
Terwin
 
$_POST['disp'] was the way to go.. thanks for clearing that up. I just upgraded from 4.0.4 to 4.2, and I guess that's just one of those tidbits I didn't pick up in the move.

Thanks a lot,
Terwin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top