0

For example, the website https://talky.io/ has a form on its homepage. When you enter text into the form and hit the button, you're taken to a page that's https://talky.io/[your text]. How do you do this? What's the best way to do it?

Thank you!

Cassidy
  • 3,328
  • 5
  • 39
  • 76

6 Answers6

1

You can use onSubmit and change the action attribute of the form via javascript, then return true. The code could look like this:

HTML from linked page:

<form id="createRoom">
   <input id="sessionInput" placeholder="Name the conversation" autofocus="autofocus">
   <button type="submit">Let’s go!</button>
</form>

Js code:

document.getElementById("crateRoom").onsubmit = function(){
   var url = encodeURIComponent(document.getElementById("sessionInput").value);
   document.getElementById("crateRoom").action = "/" + url;
   return true;
}
Tomas Nekvinda
  • 524
  • 1
  • 5
  • 15
0

It is server-side script job. You can look at some MVC framework and the url parameters

Rikky
  • 515
  • 3
  • 8
0

You can use PHP symfony or codeignitor, if you use .net then create a new MVC project.

But if you only need to change urls like

www.mysite.com/mypage.php?something=value

to

www.mysite.com/value

You can do a mod rewrite in apache or if you're using .net then use RegisterRoutes in your global.asax.cs

HMR
  • 37,593
  • 24
  • 91
  • 160
  • So what if we're not using .NET nor PHP? What's another alternative? – Cassidy Jul 13 '13 at 07:32
  • @CassidyWilliams What are you using? – HMR Jul 13 '13 at 07:34
  • @CassidyWilliams I am assuming you know about POST, GET, PUT and DELETE requests and we're talking about how to implement SEO friendly url's like the one used on this site or like `www.myblog.com/camping_in_guilin` instead of `www.myblog.com/article.php?articleid=22` – HMR Jul 13 '13 at 07:45
0

You can use GET method of form;for example:

<form action="index.php" method="get">
Page: <input type="text" name="page">
<input type="submit" value="Submit">
</form>

that after submit will go to index.php?page=yourEnteredPage.

Majid
  • 13,853
  • 15
  • 77
  • 113
0

Using a form you can submit data to a location/url that was given in the action attribute of the for, for example

<form method="POST" action="http://example.com">
    <input name="first_name" type="text" value="" />
    <!-- Form elements -->
    <input type="submit" name="mySubmitButton" value="Submit">
</form>

This form will submit the form data to the given action url when submit will be pressed and on the derver data could be retrieve using

$first_name = $_POST['first_name';];

and so on. The method POST is used to submit the form in the post array so you can retrieve data using $_POST['formfieldname'] and if you use method="GET" then you can get submitted data from $_GET variable, like, $fname=$_GET['first_name']. GET has limitation of amount when submitting data (safe to use up to 2000 characters IE's limit) and is visible to address bar of the browser and not being used for login (password) and POST can send more data than GET and also not visible to address bar. You may read this.

Community
  • 1
  • 1
The Alpha
  • 143,660
  • 29
  • 287
  • 307
0

Fairly possible with URL Rewriting http://en.wikipedia.org/wiki/Rewrite_engine

  • Note that [link-only answers](http://meta.stackoverflow.com/tags/link-only-answers/info) are discouraged, SO answers should be the end-point of a search for a solution (vs. yet another stopover of references, which tend to get stale over time). Please consider adding a stand-alone synopsis here, keeping the link as a reference. – kleopatra Oct 21 '13 at 08:17