Meloun
Meloun

Reputation: 15069

form send method GET and htacces

I have cool uri in format

page.com/par1/par2/par3

But on this page is form, that send data with GET method, so I get again

page.com/?p1=par1&p2=par2&p3=par3

Maybe form has to have send data to some script(action="redirect.php"), that make cool uri for me?

header("Location: http://www.server.com/$_GET[p1]/$_GET[p2]/$_GET[p2]");

Is there any another solution?

Upvotes: 1

Views: 191

Answers (2)

Eric Brandel
Eric Brandel

Reputation: 880

I think your solution is better than this, but you could utilize some jQuery/javascript that would redirect you to a URL that you built in that format. This probably isn't 100% valid javascript, but something like this would work:

Assuming that the fields holding the parameters have the IDs of par1, par2, and par3:

function fakeSubmit() {
    var coolURL = "http://page.com/" + $("#par1").val() + "/" +  
                  $("#par2").val() + "/" +  $("#par3").val() + "/";
    window.location.href = coolURL;
}

Then just have your button call that when it's clicked:

<input type="button" onclick="fakeSubmit()" value="Click Me!" />

Upvotes: 3

jap1968
jap1968

Reputation: 7763

You can try to modify the "action" tag of your "form" with a javascript funcion based on the values of your form fields.

You can fire the javascript function by means of the "onsubmit()" method.

Upvotes: 0

Related Questions