November 6, 201015 yr Can anyone tell me how to go to a particular page when a submit button is pressed please? For example, I want to be able to type different postcodes into an input field but for them all to go to the same URL plus the postcode e.g. When LL56 4PE is typed into the input field I want it to redirect to www.whatever.com/map#search/LL56 4PE Does that make sense!? Thanks for your help in advance!
November 6, 201015 yr Can anyone tell me how to go to a particular page when a submit button is pressed please? For example, I want to be able to type different postcodes into an input field but for them all to go to the same URL plus the postcode e.g. When LL56 4PE is typed into the input field I want it to redirect to www.whatever.com/map#search/LL56 4PE Does that make sense!? Thanks for your help in advance! <?php if(isset($_POST['submit'])){ header("Location:www.whatever.com/map#search/LL56 4PE"); exit(); } ?>
November 7, 201015 yr Author <?php if(isset($_POST['submit'])){ header("Location:www.whatever.com/map#search/LL56 4PE"); exit(); } ?> Thanks you for that. However, won't that just take me to LL56 4PE every time? I want whatever postcode the user puts in the input field to be placed at the end of the URL. For example: - If they typed in LL56 1LS into the input field and pressed submit it would go to www.whatever.com/map#search/LL56 1LS - If they typed in LL56 2QZ into the input field and pressed submit it would go to www.whatever.com/map#search/LL56 2QZ ...and so on.
November 8, 201015 yr Author Actually, seeing as this is now a PHP query...can I move it to the PHP section please? Thank you!
November 8, 201015 yr It will be more like: <?php if(isset($_POST['submit'])){ header("Location:www.whatever.com/map#search/$PostCode"); exit(); } ?> Then for the postcode field: <input type="text" name="PostCode"> You'll also need to tell the form to GET the postcode: $PostCode = $_GET["PostCode"]; Something like this should work, see here for more: http://www.w3schools.com/PHP/php_get.asp
November 9, 201015 yr This could actually just be done with javascript really if you want to just change the url
November 9, 201015 yr Author Cheers Daz. I've got a feeling I'm not doing it right though!! (The fact it's not working gave it away!) I have 2 pages. The first page has the form: <form action="map.php" method="get"> <input type="text" name="PostCode" /> <input type="submit" class="bigButton" /> </form> I then have a PHP file that has the following code in it (nothing else): <?php $PostCode = $_GET["PostCode"]; if(isset($_POST['submit'])){ header("Location:http://www.whatever.com/map#search/$PostCode"); exit(); } ?> Can you (or anyone else) tell me where I'm going wrong please? Thank you! I really need to learn PHP!!
November 9, 201015 yr Author This could actually just be done with javascript really if you want to just change the url Jay, been trying to get hold of you. Check your email!
November 9, 201015 yr Cheers Daz. I've got a feeling I'm not doing it right though!! (The fact it's not working gave it away!) I have 2 pages. The first page has the form: <form action="map.php" method="get"> <input type="text" name="PostCode" /> <input type="submit" class="bigButton" /> </form> I then have a PHP file that has the following code in it (nothing else): <?php $PostCode = $_GET["PostCode"]; if(isset($_POST['submit'])){ header("Location:http://www.whatever.com/map#search/$PostCode"); exit(); } ?> Can you (or anyone else) tell me where I'm going wrong please? Thank you! I really need to learn PHP!! try including the PHP inside the same page as the form and switching the form's action to the same page it's on too? What happens exactly, any error messages?
November 9, 201015 yr Ah I forgot to say, you need to use either $_GET or $_POST, you're using both. Your form has get as the method, so change the $_POST['submit'] //to $_GET['submit'] You should also do some text cleaning, to avoid people putting in random crap
Create an account or sign in to comment