Jump to content

Form submit without query parameters - alternate URLs.


LLLLLLL

Recommended Posts

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.

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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.