Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you direct to a page according to what's typed into a form?

Status
Not open for further replies.

meeble

Programmer
Sep 24, 2002
137
GB
Hello,

I have a form and when the user types in any of 3 words and presses submit I want them to go to a certain page. If they don't type in any of the three words I want a little box to pop up saying they haven't entered a correct word.

How can you do this please?

James
 
For the pop-up add this to your form tag:

name="frmTest" ONSUBMIT="return DataValidation();"

in your head tags add this:

<SCRIPT LANGUAGE="JavaScript">
<!--

function DataValidation()
{

if (document.frmTest.nameOfField.value == "") {

alert("You must enter a value for the word!");
return false;

}
return true;

}

// -->
</SCRIPT>

When faced with a decision, always ask, 'Which would be the most fun?'
 
This question - and similar client i.e. browser side questions - is best answered by the friendly folks in the Javscript forum.

PHP runs on the server, it does all its work before the page content is sent to the browser. Thus, the PHP forum will not get you the expert answers you will get in the JavaScript forum!
Cheers.
 
But I want this done in PHP not JavaScript.

I assumed it was just a PHP IF ELSE clause on the second page, no?
 
yes:
<?
$nameOfField=$_POST["nameOfField"]; //assumed to be post method.

if($nameOfField!="TheCombo")
{
?>
<script>
alert("wrong combo")
history.back()
</script>
<?
exit();
}
else
{
//Its correct
header("Location:ThePhpPage");
}
?>

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top