Jump to content

If a form submits back to same page do you need to use $get


deansaddigh

Recommended Posts

IM trying to pass page number and year that was selected back to the same page.

 

i have this code

echo '<form action="archivedBookings.php" method="get">';
						 echo '<select name="year" class="dropdown" onChange="this.form.submit()" >';

 

Which submits the form when the user selects a year from the drop down box and

 

<option value="<?=$this_page.'&$year'?>" <? if($_GET{'year'}){echo 'selected';}?>><?=$year?></option>

 

the code above, should send through the page variable and the year variable that was selected.

The selected part i dont know what that does and when the page submits i get a crazy url

that looks like this

 

http://www.dhcottages.co.uk/testsite/admin/archivedBookings.php?year=http%3A%2F%2Fwww.dhcottages.co.uk%2Ftestsite%2Fadmin%2Fbookings%2FarchivedBookings.php%26%24year

 

Can anyone point me in the right direction a tall?

 

 

whether you should use $_GET or $_POST depends on the <form method>

 

the value of $this_page must be the URL of the page itself. it looks like your code is working, but you're confusing what you're putting in the <option value>

 

I don't understand your reason for doing this but? The user loads the page, selects a year from the drop down box, then the form submits and loads again and you want the year to be auto selected in the dropdown box if $_GET['year'] exists? Why not just not submit the form and let the user select the year?!!?!

Ok im confusing myself aswell.

In lamens terms all i want is the user can select a date and then records show up for that date.

 

I found out what $this_page does

 

$this_page ="http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"; 

This

<option value="<?=$this_page.'&$year'?>" <? if($_GET{'year'}){echo 'selected';}?>><?=$year?></option>

Should be

<option value="<?=$year?>" <? if($_GET{'year'}){echo 'selected';}?>><?=$year?></option>

Thats wicked

 

i did have this for the form value as well

 echo '<form action="archivedBookings.php" method="get">';

 

which obviously just needed to be <form>

 

am i right

No, leave it as it is. The form tag should have an action and method defined.

my appolagise, when i keep the

 echo '<p> view Archived by year</p>';
						 echo '<form action="archivedBookings.php" method="get">';
						 echo '<select name="year" class="dropdown" onChange="this.form.submit()" >';

						 // Loop through the entries and print out a dropdown
						 for ( $counter = 0; $counter <= $totalyears; $counter ++) 
						 {	
						 	$year = $oldestdateyear + $counter;
							?>
                               <option value="<?=$year?>" <? if($_GET{'year'}){echo 'selected';}?>><?=$year?></option>

							<?
						 }
						  
						 echo '</select>';
						 echo '</form>';

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.