Form field entry directs to diff URLs based on entry?

Discussion in 'HTML' started by AtomicBob, Apr 29, 2006.

  1. AtomicBob

    AtomicBob Guest

    I have been given an interesting task:

    Make a page with a single form field, which is to take a name (first
    and last), and regardless of case or whether there is a space between
    the first and last name, when the user hits the submit button it takes
    them to a URL that has been assigned to that name.

    Example 1:

    user enters "Tony Tiger" in the field and hits submit.

    user is then sent to tonytiger.exampledomain.com.

    Example 2:

    user enters "johnnywalker" in the field and hits submit.

    user is then sent to johnnywalker.exampledomain.com.

    Thanks very much for any advice!
     
    AtomicBob, Apr 29, 2006
    #1
    1. Advertising

  2. AtomicBob

    Martin Jay Guest

    In message <>,
    AtomicBob <> writes
    >I have been given an interesting task:
    >
    >Make a page with a single form field, which is to take a name (first
    >and last), and regardless of case or whether there is a space between
    >the first and last name, when the user hits the submit button it takes
    >them to a URL that has been assigned to that name.


    I've upload something to get your started to:
    <http://www.spam-free.org.uk/pages/login.zip>.

    It's a bit basic, and you might want to think about what should happen
    if someone enters a name that doesn't exist.

    Presumably this is for a referrals type application and security isn't
    an issue.
    --
    Martin Jay
    Phone/SMS: +44 7740 191877
    Fax: +44 870 432 5180
     
    Martin Jay, Apr 29, 2006
    #2
    1. Advertising

  3. "Martin Jay" <> skrev i meddelandet
    news:...
    > In message <>,
    > AtomicBob <> writes
    > >I have been given an interesting task:
    > >
    > >Make a page with a single form field, which is to take a name (first
    > >and last), and regardless of case or whether there is a space between
    > >the first and last name, when the user hits the submit button it takes
    > >them to a URL that has been assigned to that name.

    >
    > I've upload something to get your started to:
    > <http://www.spam-free.org.uk/pages/login.zip>.
    >
    > It's a bit basic, and you might want to think about what should happen
    > if someone enters a name that doesn't exist.



    What do you think it would happen?


    --
    Luigi Donatello Asero
    https://www.scaiecat-spa-gigi.com/sv/faktaomitalien.php
    今天二零零六年四月二åä¹æ—¥
    星期五六
     
    Luigi Donatello Asero, Apr 29, 2006
    #3
  4. AtomicBob

    Martin Jay Guest

    In message <P5P4g.54926$>, Luigi Donatello
    Asero <> writes
    >"Martin Jay" <> skrev i meddelandet
    >news:...
    >> In message <>,
    >> AtomicBob <> writes
    >> >I have been given an interesting task:
    >> >
    >> >Make a page with a single form field, which is to take a name (first
    >> >and last), and regardless of case or whether there is a space between
    >> >the first and last name, when the user hits the submit button it takes
    >> >them to a URL that has been assigned to that name.


    >> I've upload something to get your started to:
    >> <http://www.spam-free.org.uk/pages/login.zip>.
    >>
    >> It's a bit basic, and you might want to think about what should happen
    >> if someone enters a name that doesn't exist.


    >What do you think it would happen?


    It depends how the server is configured: visitors may get a 'server not
    found' error, a 404 error, a default page, or maybe something else.

    The script could be modified to deal with unexpected names, either by
    looking names up in a database or checking them against a list. Or they
    could be hard-coded into it. :(
    --
    Martin Jay
     
    Martin Jay, Apr 29, 2006
    #4
  5. "Martin Jay" <> skrev i meddelandet
    news:...
    > In message <P5P4g.54926$>, Luigi Donatello
    > Asero <> writes
    > >"Martin Jay" <> skrev i meddelandet
    > >news:...
    > >> In message <>,
    > >> AtomicBob <> writes
    > >> >I have been given an interesting task:
    > >> >
    > >> >Make a page with a single form field, which is to take a name (first
    > >> >and last), and regardless of case or whether there is a space between
    > >> >the first and last name, when the user hits the submit button it takes
    > >> >them to a URL that has been assigned to that name.

    >
    > >> I've upload something to get your started to:
    > >> <http://www.spam-free.org.uk/pages/login.zip>.
    > >>
    > >> It's a bit basic, and you might want to think about what should happen
    > >> if someone enters a name that doesn't exist.

    >
    > >What do you think it would happen?

    >
    > It depends how the server is configured: visitors may get a 'server not
    > found' error, a 404 error, a default page, or maybe something else.
    >
    > The script could be modified to deal with unexpected names, either by
    > looking names up in a database or checking them against a list. Or they
    > could be hard-coded into it. :(
    > --
    > Martin Jay


    Do you mean that if an user should fill in a form like this
    https://www.scaiecat-spa-gigi.com/sv/formularet.html
    and write a name
    which does not exist, this user would get a 404 error?!

    --
    Luigi Donatello Asero
    https://www.scaiecat-spa-gigi.com/sv/faktaomitalien.php
    今天二零零六年四月二åä¹æ—¥
    星期五六
     
    Luigi Donatello Asero, Apr 29, 2006
    #5
  6. In alt.html, Luigi Donatello Asero wrote:

    > Do you mean that if an user should fill in a form like this
    > https://www.scaiecat-spa-gigi.com/sv/formularet.html and write a name
    > which does not exist, this user would get a 404 error?!


    Pay attention, Luigi.

    --
    -bts
    -Warning: I brake for lawn deer
     
    Beauregard T. Shagnasty, Apr 29, 2006
    #6
  7. AtomicBob

    Toby Inkster Guest

    AtomicBob wrote:

    > Example 1:
    > user enters "Tony Tiger" in the field and hits submit.
    > user is then sent to tonytiger.exampledomain.com.
    >
    > Example 2:
    > user enters "johnnywalker" in the field and hits submit.
    > user is then sent to johnnywalker.exampledomain.com.


    Unless you use some client-side scripting, a form will always submit to
    just one place.

    However, that one place could be a script that looks at the form
    submission and sends an HTTP 301 redirect to various different places
    based on the form contents.

    Here's some example code:

    <form action="redirect.php" method="get">
    <fieldset>
    <legend>enter a name</legend>
    <input name="name">
    <input type="submit">
    </fieldset>
    </form>

    <?php
    // This file is "redirect.php".

    // What is my domain name?
    $mydomain = 'example.com';

    // You used 'exampledomain.com' -- you might not have known
    // that there exists a domain 'example.com' which is specially
    // reserved just for examples.

    // What name has the user entered?
    $name = $_GET['name'];

    // Convert down to lower case
    $name = StrToLower($name);

    // Remove all characters except 0-9 and a-z
    $name = pReg_Replace('/[^0-9a-z]/', '', $name);

    // Generate Final URL
    $url = "http://{%s}.{$mydomain}/";

    // Redirect
    Header("HTTP/1.1 301 Redirect");
    Header("Location: {$url}");
    ?>

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
     
    Toby Inkster, Apr 29, 2006
    #7
  8. "Toby Inkster" <> skrev i meddelandet
    news:5n.co.uk...
    > AtomicBob wrote:
    >
    > > Example 1:
    > > user enters "Tony Tiger" in the field and hits submit.
    > > user is then sent to tonytiger.exampledomain.com.
    > >
    > > Example 2:
    > > user enters "johnnywalker" in the field and hits submit.
    > > user is then sent to johnnywalker.exampledomain.com.

    >
    > Unless you use some client-side scripting, a form will always submit to
    > just one place.
    >
    > However, that one place could be a script that looks at the form
    > submission and sends an HTTP 301 redirect to various different places
    > based on the form contents.
    >
    > Here's some example code:
    >
    > <form action="redirect.php" method="get">
    > <fieldset>
    > <legend>enter a name</legend>
    > <input name="name">
    > <input type="submit">
    > </fieldset>
    > </form>
    >
    > <?php
    > // This file is "redirect.php".
    >
    > // What is my domain name?
    > $mydomain = 'example.com';
    >
    > // You used 'exampledomain.com' -- you might not have known
    > // that there exists a domain 'example.com' which is specially
    > // reserved just for examples.
    >
    > // What name has the user entered?
    > $name = $_GET['name'];
    >
    > // Convert down to lower case
    > $name = StrToLower($name);
    >
    > // Remove all characters except 0-9 and a-z
    > $name = pReg_Replace('/[^0-9a-z]/', '', $name);
    >
    > // Generate Final URL
    > $url = "http://{%s}.{$mydomain}/";
    >
    > // Redirect
    > Header("HTTP/1.1 301 Redirect");
    > Header("Location: {$url}");
    > ?>
    >
    > --
    > Toby A Inkster BSc (Hons) ARCS
    > Contact Me ~ http://tobyinkster.co.uk/contact


    How does the file redirect.php file decide to which URL it shall send the
    form content?

    --
    Luigi Donatello Asero
    https://www.scaiecat-spa-gigi.com/it/svezia.html
    今天二零零六年四月二åä¹æ—¥
    星期五六
     
    Luigi Donatello Asero, Apr 29, 2006
    #8
  9. AtomicBob

    Martin Jay Guest

    In message <MEP4g.54930$>, Luigi Donatello
    Asero <> writes
    >"Martin Jay" <> skrev i meddelandet
    >news:...
    >> In message <P5P4g.54926$>, Luigi Donatello
    >> Asero <> writes
    >> >"Martin Jay" <> skrev i meddelandet
    >> >news:...


    >> >> It's a bit basic, and you might want to think about what should happen
    >> >> if someone enters a name that doesn't exist.


    >> >What do you think it would happen?


    >> It depends how the server is configured: visitors may get a 'server not
    >> found' error, a 404 error, a default page, or maybe something else.
    >>
    >> The script could be modified to deal with unexpected names, either by
    >> looking names up in a database or checking them against a list. Or they
    >> could be hard-coded into it. :(


    >Do you mean that if an user should fill in a form like this
    >https://www.scaiecat-spa-gigi.com/sv/formularet.html
    > and write a name
    >which does not exist, this user would get a 404 error?!


    Swedish? Unfortunately the English version of the page isn't available
    yet. :(

    My comments were not about forms in general, but specifically about the
    setup described by AtomicBob at the beginning of the thread.
    --
    Martin Jay
     
    Martin Jay, Apr 29, 2006
    #9
  10. "Luigi Donatello Asero" <> skrev i meddelandet
    news:eDQ4g.54935$...
    >
    > "Toby Inkster" <> skrev i meddelandet
    > news:5n.co.uk...
    > > AtomicBob wrote:
    > >
    > > > Example 1:
    > > > user enters "Tony Tiger" in the field and hits submit.
    > > > user is then sent to tonytiger.exampledomain.com.
    > > >
    > > > Example 2:
    > > > user enters "johnnywalker" in the field and hits submit.
    > > > user is then sent to johnnywalker.exampledomain.com.

    > >
    > > Unless you use some client-side scripting, a form will always submit to
    > > just one place.
    > >
    > > However, that one place could be a script that looks at the form
    > > submission and sends an HTTP 301 redirect to various different places
    > > based on the form contents.
    > >
    > > Here's some example code:
    > >
    > > <form action="redirect.php" method="get">
    > > <fieldset>
    > > <legend>enter a name</legend>
    > > <input name="name">
    > > <input type="submit">
    > > </fieldset>
    > > </form>
    > >
    > > <?php
    > > // This file is "redirect.php".
    > >
    > > // What is my domain name?
    > > $mydomain = 'example.com';
    > >
    > > // You used 'exampledomain.com' -- you might not have known
    > > // that there exists a domain 'example.com' which is specially
    > > // reserved just for examples.
    > >
    > > // What name has the user entered?
    > > $name = $_GET['name'];
    > >
    > > // Convert down to lower case
    > > $name = StrToLower($name);
    > >
    > > // Remove all characters except 0-9 and a-z
    > > $name = pReg_Replace('/[^0-9a-z]/', '', $name);
    > >
    > > // Generate Final URL
    > > $url = "http://{%s}.{$mydomain}/";
    > >
    > > // Redirect
    > > Header("HTTP/1.1 301 Redirect");
    > > Header("Location: {$url}");
    > > ?>
    > >
    > > --
    > > Toby A Inkster BSc (Hons) ARCS
    > > Contact Me ~ http://tobyinkster.co.uk/contact

    >
    > How does the file redirect.php file decide to which URL it shall send the
    > form content?



    Do you mean perhaps that it will show a page with 404 error to the user if
    he or she has filled in the form a name which contains forbidden
    characters?


    --
    Luigi Donatello Asero
    https://www.scaiecat-spa-gigi.com/sv/faktaomitalien.php
    今天二零零六年四月二åä¹æ—¥
    星期五六
     
    Luigi Donatello Asero, Apr 29, 2006
    #10
  11. "Martin Jay" <> skrev i meddelandet
    news:...
    > In message <MEP4g.54930$>, Luigi Donatello
    > Asero <> writes
    > >"Martin Jay" <> skrev i meddelandet
    > >news:...
    > >> In message <P5P4g.54926$>, Luigi Donatello
    > >> Asero <> writes
    > >> >"Martin Jay" <> skrev i meddelandet
    > >> >news:...

    >
    > >> >> It's a bit basic, and you might want to think about what should

    happen
    > >> >> if someone enters a name that doesn't exist.

    >
    > >> >What do you think it would happen?

    >
    > >> It depends how the server is configured: visitors may get a 'server not
    > >> found' error, a 404 error, a default page, or maybe something else.
    > >>
    > >> The script could be modified to deal with unexpected names, either by
    > >> looking names up in a database or checking them against a list. Or

    they
    > >> could be hard-coded into it. :(

    >
    > >Do you mean that if an user should fill in a form like this
    > >https://www.scaiecat-spa-gigi.com/sv/formularet.html
    > > and write a name
    > >which does not exist, this user would get a 404 error?!

    >
    > Swedish? Unfortunately the English version of the page isn't available
    > yet. :(



    As my one-man business is in Sweden , I usually write the pages in Swedish
    first, I often write the pages in Italian ( I am Italian and I was grown up
    in Italy
    and in German afterwards.....English is not my first priority on the
    website.. so I usually write the pages in English later
    because there are many more competiting pages in the English language than
    for example in Swedish or Finnish or Italian..
    Why should I show the content to competitors before I display them to
    customers?
    (they often understand English...)


    > My comments were not about forms in general, but specifically about the
    > setup described by AtomicBob at the beginning of the thread.


    Ok.
    The thread is interesting anyway....

    --
    Luigi Donatello Asero
    https://www.scaiecat-spa-gigi.com/sv/europa/italien/markerna/ancona/numana/
    今天二零零六年四月二åä¹æ—¥
    星期五六



    https://www.scaiecat-spa-gigi.com/sv/europa/italien/markerna/ancona/numana/
     
    Luigi Donatello Asero, Apr 29, 2006
    #11
  12. "Luigi Donatello Asero" <> skrev i meddelandet
    news:eek:1R4g.54943$...
    >
    > "Martin Jay" <> skrev i meddelandet
    > news:...
    > > In message <MEP4g.54930$>, Luigi Donatello
    > > Asero <> writes
    > > >"Martin Jay" <> skrev i meddelandet
    > > >news:...
    > > >> In message <P5P4g.54926$>, Luigi Donatello
    > > >> Asero <> writes
    > > >> >"Martin Jay" <> skrev i meddelandet
    > > >> >news:...

    > >
    > > >> >> It's a bit basic, and you might want to think about what should

    > happen
    > > >> >> if someone enters a name that doesn't exist.

    > >
    > > >> >What do you think it would happen?

    > >
    > > >> It depends how the server is configured: visitors may get a 'server

    not
    > > >> found' error, a 404 error, a default page, or maybe something else.
    > > >>
    > > >> The script could be modified to deal with unexpected names, either by
    > > >> looking names up in a database or checking them against a list. Or

    > they
    > > >> could be hard-coded into it. :(

    > >
    > > >Do you mean that if an user should fill in a form like this
    > > >https://www.scaiecat-spa-gigi.com/sv/formularet.html
    > > > and write a name
    > > >which does not exist, this user would get a 404 error?!

    > >
    > > Swedish? Unfortunately the English version of the page isn't available
    > > yet. :(

    >
    >
    > As my one-man business is in Sweden , I usually write the pages in

    Swedish
    > first, I often write the pages in Italian ( I am Italian and I was grown

    up
    > in Italy



    I grew up in Italy and I lived some years in Germany. Germany is an
    important commercial partner for both Sweden and Italy.
    At the same time there are less people speaking for example German, Swedish
    and Italian than English...
    Not every European speaks Chinese either which is one of the reasons why I
    am learning Chinese....


    --
    Luigi Donatello Asero
    https://www.scaiecat-spa-gigi.com/sv/europa/italien/markerna/ancona/numana/
    今天二零零六年四月二åä¹æ—¥
    星期五六
     
    Luigi Donatello Asero, Apr 29, 2006
    #12
  13. Luigi Donatello Asero wrote:
    > "Luigi Donatello Asero" <> skrev i meddelandet
    > news:eDQ4g.54935$...
    >> "Toby Inkster" <> skrev i meddelandet

    <snip>
    >>> // Convert down to lower case
    >>> $name = StrToLower($name);
    >>>
    >>> // Remove all characters except 0-9 and a-z
    >>> $name = pReg_Replace('/[^0-9a-z]/', '', $name);


    <snip>

    > Do you mean perhaps that it will show a page with 404 error to the user if
    > he or she has filled in the form a name which contains forbidden
    > characters?



    Not necessarily. If you look at the function, he is stripping out all
    non-alpha numeric characters, if what is left matches a page that exists
    then it would be valid else you would get the 404. Of course one would
    normally use the cleaned form input and look up from either a listing or
    database for the file. If not found it could use a fall-back page with a
    Table of Contents of valid filenames/urls.

    --
    Take care,

    Jonathan
    -------------------
    LITTLE WORKS STUDIO
    http://www.LittleWorksStudio.com
     
    Jonathan N. Little, Apr 29, 2006
    #13
  14. AtomicBob

    Dustin Guest

    This seems a lot easier to me using JavaScript

    <html>
    <head>
    <script>
    function redirect()
    {
    var domain = "exampledomain.com";
    var name = document.getElementById("name").value;
    name = name.toLowerCase(); //put everthing in lower case
    name = name.replace(" ", "");
    document.location.href = "http://" + name + "." + domain;
    }
    </script>
    </head>
    <body>
    Name: <input type="text" id="name" /><br />
    <button onclick="javascript:redirect()">Submit</button>
    </body>
    </html>
     
    Dustin, May 2, 2006
    #14
  15. AtomicBob

    Toby Inkster Guest

    Dustin wrote:

    > <script>
    > function redirect()
    > {
    > var domain = "exampledomain.com";
    > var name = document.getElementById("name").value;
    > name = name.toLowerCase(); //put everthing in lower case
    > name = name.replace(" ", "");
    > document.location.href = "http://" + name + "." + domain;
    > }
    > </script>


    What if the user doesn't have Javascript enabled? Important things like
    navigation shouldn't rely on client-side scripting.

    What if they type in the name "John O'Groats"? Treat all user input as
    hostile by default.

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
     
    Toby Inkster, May 2, 2006
    #15
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Cyril Vi?ville

    diff Process under diff users

    Cyril Vi?ville, Jun 29, 2004, in forum: Perl
    Replies:
    1
    Views:
    513
    Joe Smith
    Jun 29, 2004
  2. Familyman
    Replies:
    1
    Views:
    387
    Familyman
    Nov 2, 2005
  3. Familyman
    Replies:
    4
    Views:
    2,979
    Jonathan N. Little
    Nov 2, 2005
  4. Donn Cave
    Replies:
    0
    Views:
    405
    Donn Cave
    Apr 11, 2008
  5. Paul

    ASP Page to cycle re-directs

    Paul, Apr 4, 2009, in forum: ASP General
    Replies:
    1
    Views:
    131
Loading...

Share This Page