user1946705
user1946705

Reputation: 2888

PHP - how to set up URL after sending form?

I have a website (www.website.com) and on the homepage is a form, where the user set up a city. After sending the form, I am trying to have the following URL address:

www.website.com/city-name

But I am lost a bit here, because I am not sure, how to set up the form (GET or POST is better for this need?), and .htaccess.

Could anyone help with this? Thank you

Upvotes: 0

Views: 147

Answers (2)

JeroenD
JeroenD

Reputation: 353

You could let the submit button run a javascript function. In that javascript function, use

var cityName = document.getElementById("the textarea id").value

to get the value the user typed for the city name. Then redirect to the right page:

window.location='http://www.website.com/' + cityName

Upvotes: 0

intelis
intelis

Reputation: 8068

After the form is submitted you could redirect your users via PHP redirect, or am i missing something?

header('Location: http://www.website.com/city-name');

But be careful, this can only be used before you send any output!

PHP: header()

Upvotes: 2

Related Questions