LLLLLLL Posted November 22, 2011 Share Posted November 22, 2011 Bear with me on the description here.... I have a pretty standard form with a select box: <form method="get" action="index.php"> <select name="category"> So this creates a URL like "index.php?category=123". All is well and good. To make the category pages more SEO friendly, I'm trying to eliminate the "index.php?" part of the url, and just have category=123. I know how to make .htaccess do a back-side redirection of category=123 to index.php?category=123. My question is, is there a way on the form to make submission of the form go to category=123 instead of index.php?category=123 ? I think the only method is to change the submit button on the form to be a javascript function (as opposed to a form submit button) that manually determines the URL to visit by concatenating the get parameters and opening the page. I don't know if there's a way to do this within a standard form/submit type of method. Quote Link to comment https://forums.phpfreaks.com/topic/251647-form-submit-without-query-parameters-alternate-urls/ Share on other sites More sharing options...
unlishema.wolf Posted November 22, 2011 Share Posted November 22, 2011 Can you provide a little more detail and maybe an example of how your select box is set up? I think I may have a solution. Edit: like how do you put the url together? Example: (prob has a few errors lol but good enough to explain what i mean i think) <?php if(isset($_POST['catagory'])) { $URL="index.php?catagory=".$_POST['category']; header("Location: ".$URL); } ?> <form method="get" action="index.php"> <select name="category"><option value='123' selected>123</option><option value='124'>124</option></select> Quote Link to comment https://forums.phpfreaks.com/topic/251647-form-submit-without-query-parameters-alternate-urls/#findComment-1290603 Share on other sites More sharing options...
LLLLLLL Posted November 22, 2011 Author Share Posted November 22, 2011 I don't see how the select box is the question; it could be a textbox or whatever. I just want to know how to make the action URL be mysite.com/store/category=abc instead of mysite.com/store/index.php?category=abc Quote Link to comment https://forums.phpfreaks.com/topic/251647-form-submit-without-query-parameters-alternate-urls/#findComment-1290609 Share on other sites More sharing options...
unlishema.wolf Posted November 22, 2011 Share Posted November 22, 2011 Submitting the fourm like you have it sends it to index.php not index.php?catagory=123 there is a $_POST['catagory'] which will give you the catagory they selected. Quote Link to comment https://forums.phpfreaks.com/topic/251647-form-submit-without-query-parameters-alternate-urls/#findComment-1290611 Share on other sites More sharing options...
LLLLLLL Posted November 22, 2011 Author Share Posted November 22, 2011 Yes, my question all along is: how can I change the action URL to be category=blah instead of index.php?category=blah Quote Link to comment https://forums.phpfreaks.com/topic/251647-form-submit-without-query-parameters-alternate-urls/#findComment-1290613 Share on other sites More sharing options...
unlishema.wolf Posted November 22, 2011 Share Posted November 22, 2011 That form does NOT go to mysite.com/store/index.php?catagory=blah. It only goes to mysite.com/store/index.php. It has a $_POST[''] for the catagory. NOT a $_GET['']. You are going to have to post more code or explain in better detail for help. You don't tell us how you create the url. You just say you use a Select Box. Maybe post the options and the rest of the form code? So this creates a URL like "index.php?category=123". All is well and good. You can always edit the code to remove stuff you don't want others to see. Make an example, it don't have to be your exact source. But it needs to be a good enough source for other people to work from. You can't expect us to read your mind. Quote Link to comment https://forums.phpfreaks.com/topic/251647-form-submit-without-query-parameters-alternate-urls/#findComment-1290616 Share on other sites More sharing options...
LLLLLLL Posted November 23, 2011 Author Share Posted November 23, 2011 You clearly have no idea what I want to accomplish. And yes, the form goes to index.php?category=blah. I'm not sure why you're being so unhelpful. Let's say wikipedia had a select box with choices of Hydrogen, Helium, and Oxygen. I want the form to take me to one of these. http://en.wikipedia.org/wiki/Hydrogen http://en.wikipedia.org/wiki/Helium http://en.wikipedia.org/wiki/Oxygen How would I create a form that does this? This has been my question all along. There are no get parameters in those URLs; how would you do it? I think my javascript method is the only answer. Quote Link to comment https://forums.phpfreaks.com/topic/251647-form-submit-without-query-parameters-alternate-urls/#findComment-1290619 Share on other sites More sharing options...
unlishema.wolf Posted November 23, 2011 Share Posted November 23, 2011 Sorry for not realizing you was using a get form instead of a post forum. I'll post 2 different methods to do this. $_GET[''] method <?php if(isset($_GET['catagory'])) { header('Location: ./catagory='$_GET['catagory']); } ?> <form method="get" action="index.php"> <select name="category"> <option value='123' selected>Catagory 123</option> <option value='124'>Catagory 124</option> </select> $_POST[''] method <?php if(isset($_POST['catagory'])) { header('Location: ./catagory='$_POST['catagory']); } ?> <form method="post" action="index.php"> <select name="category"> <option value='123' selected>Catagory 123</option> <option value='124'>Catagory 124</option> </select> Quote Link to comment https://forums.phpfreaks.com/topic/251647-form-submit-without-query-parameters-alternate-urls/#findComment-1290625 Share on other sites More sharing options...
LLLLLLL Posted November 23, 2011 Author Share Posted November 23, 2011 I will have to go with my javascript method, as there are more parameters than just category. I guess the actual answer to my question is that there's no way to use a standard form to do what I'm asking. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/251647-form-submit-without-query-parameters-alternate-urls/#findComment-1290627 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.