Forum Moderators: coopster

Message Too Old, No Replies

Make url with form value

         

erika03

1:12 pm on Nov 14, 2014 (gmt 0)

10+ Year Member



Hi,
i making listing site.
so,for ex. example.com
when some1 fill form name and company then i want make url for it

example.com/name/company

please help me in this issue.

Thanks in advance.

mack

5:13 pm on Nov 14, 2014 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Making the URL is only one part of the problem, you need to make sure your website is able to handle the URL structure and generate pages based on the URL perimeters. Security is also an issue because you do not want your users to be able to add additional values to the URL.

The form part is fairly easy, you simply use a form to pass the variables to the url using the GET method. This will give you something like...

example.com?name=somename&company=somecompany

What you could then do is create a php file to extract the values and do a redirect

1)get the values from the url string
2)validate that all fields are present
3)clean up the fields to remove anything you don’t want in there
4)redirect the browser to the new url

example.com/somename/somecompany

You will then need to use mod-rewrite and create rules to use the new format of url, whilst still handling it internally as the old style of url. For example the page may be somename/somecompany but the rewrite rull will handle this page as ?name=somename&company=somecompany

There are a lot of tutorials online regarding mod rewrite and shortening url's I hope this post gives you some ideas of the concept.

Mack.

spageopriya

8:08 am on Nov 21, 2014 (gmt 0)



<script>
function process()
{
var url="http://name.com/" + document.getElementById("url").value;
location.href=url;
return false;
}
</script>
<form onSubmit="return process();">
URL: <input type="text" name="url" id="url"> <input type="submit" value="go">
</form>

[edited by: engine at 8:25 am (utc) on Nov 21, 2014]
[edit reason] See WebmasterWorld TOS [/edit]