deansaddigh Posted January 10, 2010 Share Posted January 10, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/187952-if-a-form-submits-back-to-same-page-do-you-need-to-use-get/ Share on other sites More sharing options...
mapleleaf Posted January 10, 2010 Share Posted January 10, 2010 When a form submits to the same page you do not need to use $_GET. $_POST will work and might be easier for you. Quote Link to comment https://forums.phpfreaks.com/topic/187952-if-a-form-submits-back-to-same-page-do-you-need-to-use-get/#findComment-992340 Share on other sites More sharing options...
Catfish Posted January 10, 2010 Share Posted January 10, 2010 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?!!?! Quote Link to comment https://forums.phpfreaks.com/topic/187952-if-a-form-submits-back-to-same-page-do-you-need-to-use-get/#findComment-992342 Share on other sites More sharing options...
deansaddigh Posted January 10, 2010 Author Share Posted January 10, 2010 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']}"; Quote Link to comment https://forums.phpfreaks.com/topic/187952-if-a-form-submits-back-to-same-page-do-you-need-to-use-get/#findComment-992344 Share on other sites More sharing options...
wildteen88 Posted January 10, 2010 Share Posted January 10, 2010 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> Quote Link to comment https://forums.phpfreaks.com/topic/187952-if-a-form-submits-back-to-same-page-do-you-need-to-use-get/#findComment-992354 Share on other sites More sharing options...
deansaddigh Posted January 10, 2010 Author Share Posted January 10, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/187952-if-a-form-submits-back-to-same-page-do-you-need-to-use-get/#findComment-992355 Share on other sites More sharing options...
wildteen88 Posted January 10, 2010 Share Posted January 10, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/187952-if-a-form-submits-back-to-same-page-do-you-need-to-use-get/#findComment-992357 Share on other sites More sharing options...
calmchess Posted January 10, 2010 Share Posted January 10, 2010 I prefer to use sessions to hold the data when a page submits to its self......just don't forget to unset the session when through with the data. Quote Link to comment https://forums.phpfreaks.com/topic/187952-if-a-form-submits-back-to-same-page-do-you-need-to-use-get/#findComment-992358 Share on other sites More sharing options...
deansaddigh Posted January 10, 2010 Author Share Posted January 10, 2010 When i keep that in though i get a No input file specified. error? Quote Link to comment https://forums.phpfreaks.com/topic/187952-if-a-form-submits-back-to-same-page-do-you-need-to-use-get/#findComment-992359 Share on other sites More sharing options...
wildteen88 Posted January 10, 2010 Share Posted January 10, 2010 When i keep that in though i get a No input file specified. error? Leave what in? Rather than post single lines of code. Post all the code for your form. Quote Link to comment https://forums.phpfreaks.com/topic/187952-if-a-form-submits-back-to-same-page-do-you-need-to-use-get/#findComment-992360 Share on other sites More sharing options...
deansaddigh Posted January 10, 2010 Author Share Posted January 10, 2010 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>'; Quote Link to comment https://forums.phpfreaks.com/topic/187952-if-a-form-submits-back-to-same-page-do-you-need-to-use-get/#findComment-992361 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.