Click here to get back home

Form field entry directs to diff URLs based on entry?

 HomeNewsGroups | Search | About
 comp.infosystems.www.authoring.html    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Form field entry directs to diff URLs based on entry? AtomicBob 04-29-2006
Get Chitika Premium
Posted by Luigi Donatello Asero on April 29, 2006, 5:10 pm
Please log in for more thread options



> 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://./";
>
> // Redirect
> Header("HTTP/1.1 301 Redirect");
> Header("Location: ");
> ?>
>
> --
> 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
今天二零零六年四月二十九日
星期五六




Posted by Luigi Donatello Asero on April 29, 2006, 5:14 pm
Please log in for more thread options



>
> > 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://./";
> >
> > // Redirect
> > Header("HTTP/1.1 301 Redirect");
> > Header("Location: ");
> > ?>
> >
> > --
> > 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
今天二零零六年四月二十九日
星期五六




Posted by Jonathan N. Little on April 29, 2006, 6:45 pm
Please log in for more thread options


Luigi Donatello Asero wrote:
<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

Posted by Dustin on May 1, 2006, 7:04 pm
Please log in for more thread options


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>


Posted by Toby Inkster on May 2, 2006, 3:07 am
Please log in for more thread options


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


Similar ThreadsPosted
Text entry with non-European scripts December 22, 2006, 2:00 pm
Horizontal CSS list, last entry right-aligned? April 11, 2008, 3:01 pm
Making default entry in search text box disappear on click June 30, 2005, 4:10 am
Prepopulating form field August 24, 2006, 3:32 am
Restoring OTHER form field after submit September 23, 2005, 1:43 am
How to sort form field data in E-mail? December 21, 2005, 9:03 am
Is there a way to enter text into an HTML Form edit field January 29, 2005, 5:42 pm
Dynamic width of a text input field in a form November 8, 2005, 6:35 am
Correct form for file:// URLs (or why don't they work in Firefox?) January 13, 2005, 9:37 pm
Loss of Form field contents when the browser BACK button is pressed November 25, 2004, 4:57 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap