-
Thanks Jas, and dcstow. You've both been very helpful, and I think I've accomplished what I needed. I now have an input box where an inputted string is converted to lowercase, and processed, then redirecting the user to the appropriate page. Awesome!
One thing I am ehh, "semi" worried about was one of Jas' comments about a 30 or 40 case maximum. As I grow these pages, it will inevitably reach that number, and of course, for each new page I must also edit this php page. What are my options to the case method? If every "case" identically matched all my page names, would the "case method" no longer be the logical choice?
Can't I just validate, convert to lowercase, add ".html" and pass the variable directly into the location code? Therefore directing a user to the appropriate page?
-
You could, I suppose, but it would be a lot of code. A better way would be something like this:
PHP Code:
$names = array();
$urls = array();
$names[] = "BOB"; $urls[] = "bob.html";
$names[] = "BILL"; $urls[] = "bill.html";
$names[] = "BART"; $urls[] = "bart.html";
$page = array_search($name, $names);
if($page == false){
$page = "Somthing.html"; // <--Back to the form, or a not found page
}else{
$page = $urls[$page];
}
It's MUCH smaller then a case for each name. You could also pull the array out of another file, if you ever needed to. It gives you many more options.
EDIT: Oh, or the easier solution:
PHP Code:
$names = array();
$names[] = "BOB";
$names[] = "BILL";
$names[] = "BART";
$page = array_search($name, $names);
if($page == false){
$page = "Somthing.html"; // <--Back to the form, or a not found page
}else{
$page = $names[$page].'html';
}
-
This code is now presenting me with a problem in IE, and I can't for the life of me figure out why!? I am using a page called registry.php, here's the code:
PHP Code:
<?php
if(isset($_POST['Submit'])){
$name = strip_tags($_POST['name']);
$name = strtolower($name);
switch($name){
case "haynes":
$page = 'haynes.html';
break;
case "bill":
$page = 'bill.html';
break;
case "bart":
$page = 'bart.html';
break;
default:
$page = "noregistry.html";
break;
}
header("Location:$page");
}
?>
And I am using the below form to post to the script.
HTML Code:
<form name="Submit" method="post" action="registry.php">
<input type="text" name="name" class="cleardefault" size="20" value="Groom's Last Name" /><br />
<font size="-2" color="#0099FF">(Use ALL lowercase letters)</font><br /><br />
<input type="Submit" name="Submit" value="Submit" />
</form>
It works in firefox, and upon original testing, it worked in IE. Now when I test in IE it takes me to the registry.php page and stops. The script does not redirect to the appropriate case or page.
Here's the live example:
www.damartravel.com/honeymoons.html
You can see the form in the left hand column.
Here's the direct link to the page it should redirect to:
www.damartravel.com/haynes.html
Hopefully this is something silly, and one of you know what it is! lol... It's been driving me crazy all morning.
Thanks in Advance.
-
Hey guys!
The script is working fabulous :)!
Just wondering however is there a code to protect the pages? So they have to of logged in that field to get to Bob.html and so no other users can go directly to Bob.html?
Much appreciated, Keenan.
-
@TonyKing,
I'm not fluent in PHP, but as I see, your code has some errors ;)
See the header() function spec. There should always be http:// :)
Also, I suppose you should post name instead of submit
Try changing your PHPcode to:
PHP Code:
<?php
if(isset($_POST['name']))
{
$myweb = 'http://www.damartravel.com';
$name = strip_tags($_POST['name']);
$name = strtolower($name);
switch($name)
{
case "haynes":
$page = $myweb.'/haynes.html';
break;
case "bill":
$page = $myweb.'/bill.html';
break;
case "bart":
$page = $myweb.'/bart.html';
break;
default:
$page = $myweb.'/noregistry.html';
break;
}
header("Location:".$page);
}
?>
See if helps ;)
@Keenan
You should use the forum's search tool, or create a new thread instead, You should'nt hi-jack someone else's thread :)
-
Thanks ragana, your code is far more solid than my original, and I will put it to good use. The "problem" I found with my script(s) was in a javascript, as it only fails when the user pushes enter on the keyboard, instead of clicking submit.
Corresponding thread: click here
Definite improvement on the code though! Thanks :)