Passing variables with Post & if elseif statements

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
penpaper
Forum Newbie
Posts: 15
Joined: Tue May 23, 2006 6:45 pm
Location: Coudersport, PA, USA

Passing variables with Post & if elseif statements

Post by penpaper »

I created a form where user could provide info for a notice to be posted on local cable TV community channel. When the form is completed the Submit button posted the variables to a page where all user input was shown for the user to verify. When it first was uploaded, the user could use the back button to make any changes. Now the back button takes you to a blank form.

Any suggestions how to keep the PHP variables in the form when the back button is used?

Here is a small portion of the info.php file

Code: Select all

<form method="post" action="confirm.php">
		
					<div class="mediumtext1"><strong>Viewing Communities </strong></div>
							
		      <div class="note">Please specify where you want the notice shown.</div>
			  <br>
	 
            <label for="coudersport"> Coudersport&nbsp;    
          	  	<input id="coudersport" name="coudersport" type="checkbox"> &nbsp;&nbsp;&nbsp;
            </label>
            <label for="emporium">&nbsp;&nbsp; Emporium&nbsp;    
           	 	<input id="emporium" name="emporium" type="checkbox"> &nbsp;&nbsp;&nbsp;
            </label>
			   <label for="port">&nbsp;&nbsp; Port Allegany&nbsp;    
           		 <input id="port" name="port" type="checkbox"> &nbsp;&nbsp;&nbsp;
            </label>
			
         <input type="submit" name="Submit" value="Submit">

				</form>
here's a small portion of the confirm.php file

Code: Select all

<form action="edit.php" method="post">

<?  if(($coudersport != "") && ($emporium == "") && ($port == ""))
{ $where = "Coudersport";}
else if(($coudersport != "") && ($emporium != "") && ($port != "")) 
{ $where = "All Communities";}
else if (($coudersport != "") && ($emporium != "") && ($port == ""))
 { $where = "Coudersport and Emporium";} 
else if (($coudersport != "") && ($emporium == "") && ($port != "")) 
{ $where = "Coudersport and Port Allegany"; } 
else if (($coudersport == "") && ($emporium != "") && ($port == ""))
{ $where = "Emporium";} 
else if (($coudersport == "") && ($emporium != "") && ($port != ""))
{ $where = "Emporium and Port Allegany";} 
else if (($coudersport == "") && ($emporium == "") && ($port != ""))
 { $where = "Port Allegany"; } 
 ?> 


 You have chosen to have the notice appear in  <? print ($where);  ?> 
<input type="hidden" name="where" value="<? print($where);?>" /> 
<input type="submit" name="Submit" value="Edit">
</form>
Another issue occurs because I created an edit form that the confirm.php file posts to. If you make a change to the community you want the notice shown in and then post back to the confirm.php form. The change is ignored. I feel certain this is a simple thing to fix, but I can't figure it out.

Here is the edit.php file

Code: Select all

<form method="post" action="confirm.php">
			 							<div class="mediumtext1"><strong>Viewing Communities </strong></div>
		<br>
You have indicated that your message or ad should be shown in <strong><?print($where);{?></strong>. <br>
		If you want to make a change to the viewing communities, please make a new selection below.
		<br><br>
	<!-- code that prints the 'x' in the checkbox of the community selected.  If AllTowns is checked, or if all 3 communities are checked, only the AllTowns box will have the 'x'     -->

		<label for="coudy"> Coudersport&nbsp;    
          	  	<input id="coudy" name="coudy" type="checkbox"> &nbsp;&nbsp;&nbsp;
            </label>
            <label for="emp">&nbsp;&nbsp; Emporium&nbsp;    
           	 	<input id="emp" name="emp" type="checkbox"> &nbsp;&nbsp;&nbsp;
            </label>
			<label for="portA">&nbsp;&nbsp; Port Allegany&nbsp;    
           		 <input id="portA" name="portA" type="checkbox"> &nbsp;&nbsp;&nbsp;
            </label>
        			
				<?
				if(($coudy != "") && ($emp =="") && ($portA == ""))
{$where = "Coudersport";}

elseif (($coudy != "") && ($emp == "") && ($portA != ""))
 { $where = "Coudersport and Port Allegany"; }
elseif (($coudy == "") && ($emp != "") && ($portA == ""))
{ $where = "Emporium";}
elseif (($coudy == "") && ($emp != "") && ($portA != ""))
{ $where = "Emporium and Port Allegany";} 
elseif (($coudy == "") && ($emp == "") && ($portA != "")) 
{ $where = "Port Allegany"; } 
elseif(($coudy != "") && ($emp != "") && ($portA != "")) 
{ $where = "All Communities";}
elseif (($coudy != "") && ($emp != "") && ($portA == ""))
 { $where = "Coudersport and Emporium";}
?>	
		<input type="hidden" name="where" value="<? print($where);}?>" /> 


				  <input type="submit" name="Submit" value="Submit Change">
</form>
Please help! Thanks loads!
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

For the back-button form retention thing, take a look at cache-control settings using the PHP function header().

As for the other issue, typically when using a confirm page, you want to submit your form to another form of hidden vars. If everything is good, send the form by clicking a button (essentially reporting the data from a series of hidden fields). Otherwise, choose back to edit the information. I would suggest you ensure register_globals is off when doing this.
penpaper
Forum Newbie
Posts: 15
Joined: Tue May 23, 2006 6:45 pm
Location: Coudersport, PA, USA

Post by penpaper »

Thanks loads! I'll give it a try. lauren
Post Reply