Jump to content

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>';

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.