Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Ultra-simple PHP question

Ultra-simple PHP question
Thread Tools
Mac Elite
Join Date: May 2001
Location: Melbourne, Australia
Status: Offline
Reply With Quote
Mar 15, 2004, 05:28 AM
 
Hi guys!

I have a small request that I hope someone can help me out with. Here's what I want to do:

I will have a form on a html page. There will be 1 field in the form called 'Domain'.

User goes to page, and types in 'macnn.com' into the 'domain' field, and then clicks the 'Go' button (submit).

Then this will happen (sudo code):

Code:
Output to Address bar: 'http://www.' + 'Domain' + /blah
They should then be taken to the page: http://www.macnn.com/blah

Did that make sense? They type a domain, then the script adds bits to it, and sends the browser there. Do I even need PHP for this, or could I just use javascript? Post your simplest suggestions please!

(note the specific request is not relevant, I need to do this for a few sites, so I would like a simple way to simply add these fields to the end of a URL)

Thanks!! (expecting hundreds of great replies when I wake up in the morning )
     
Grizzled Veteran
Join Date: Nov 2003
Location: Hebburn, UK
Status: Offline
Reply With Quote
Mar 15, 2004, 05:39 AM
 
Code:
<html> <head> <title>whatever</title> <script> function goTo() { var domain = document.getElementById("domain").value; document.location.href = "http://www." + domain + "/blah"; } </script> </head> <body> <input type="text" id="domain"> <button onclick="goTo()">Go</button> </body> </html>
You might want some error checking, to make sure they don't submit a blank field and that they haven't typed in the www. bit too...
Just who are Britain? What do they? Who is them? And why?

Formerly Black Book
     
Occasionally Useful
Join Date: Jun 2001
Location: Liverpool, UK
Status: Offline
Reply With Quote
Mar 15, 2004, 07:55 AM
 
just whipped this up; seems to work as requested [php]<?
$domain = $HTTP_POST_VARS['domain'];
$Submit = isset($_POST['Submit']) ? TRUE : FALSE;
if($Submit){
header("Location: http://$domain/blah/");
} else {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>gigantic purple form</title>
</head>
<body>
<form name="form" id="form" method="post" action="/gpf.php">
<input name="domain" type="text" id="domain" />
<input type="submit" name="Submit" value="havoc!" />
</form>
</body>
</html>
<? } ?>[/php] have fun, jer'
"Have sharp knives. Be creative. Cook to music" ~ maxelson
     
RGB
Mac Elite
Join Date: Jan 2002
Location: College in the Land of Oz
Status: Offline
Reply With Quote
Mar 16, 2004, 02:30 AM
 
Originally posted by philzilla:
just whipped this up; seems to work as requested [php]<?
$domain = $HTTP_POST_VARS['domain'];
$Submit = isset($_POST['Submit']) ? TRUE : FALSE;
if($Submit){
header("Location: http://$domain/blah/");
} else {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>gigantic purple form</title>
</head>
<body>
<form name="form" id="form" method="post" action="/gpf.php">
<input name="domain" type="text" id="domain" />
<input type="submit" name="Submit" value="havoc!" />
</form>
</body>
</html>
<? } ?>[/php] have fun, jer'
Pretty much what I was just gonna post. Go with it.
     
Mac Elite
Join Date: May 2001
Location: Melbourne, Australia
Status: Offline
Reply With Quote
Mar 17, 2004, 12:14 AM
 
Aww, shucks. You guys spoil me

Both look good, I will check them out - cheers!
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:02 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2