Validating, then redirecting...
Posted: Mon Sep 25, 2006 8:07 am
Hi, I have a form, which sends the data to validateForm.php, so it can be validated within the validateForm.php:
What I want to do in validateForm.php....after the data are being validated and all are valid, I want the user to be redirected to another page. All this time, I am doing it by echoing <script> tag, and embed the javascript within PHP. I am wondering, if there is more efficient and prefered way of redirecting user ?
Note:
I have read the jason's tutorial about redirecting user using header() function. But in my case, the header has been sent to the output. And I am wondering if there is another way to redirect user in my case.
Thank you very much,
Chris
Code: Select all
<form method = "post" name = "registrationForm" action ="validateForm.php">
<input type ="text" name = "txtUserName"></input>
<input type="password" name = "txtPassword"></input>
</form>Note:
I have read the jason's tutorial about redirecting user using header() function. But in my case, the header has been sent to the output. And I am wondering if there is another way to redirect user in my case.
Thank you very much,
Chris
Code: Select all
<?php
session_start();
$_SESSION['username'] = $_POST['txtUserName'];
$_SESSION['password'] = $_POST['txtPassword'];
/**
* function to check form validity
* @return boolean
*/
function checkValidity() {
//the logic here...
}
$isAllValid = checkValidity();
if ($isAllValid) {
//redirect user using Javascript
echo '<script src = "validations.js" type = "text/javascript"></script>';
echo '<script language = "javascript" type = "text/javascript">';
echo 'redirectUser("registrationCompleted.php");';
echo '</script>';
}
?>