PHP, pause script until form is submitted?

james s

New member
I was wondering if there was a way to request information from a form, and when the form is submitted continue the script (such as with JavaScript event handlers) I have a user logon script which, when an instance of the class 'User' is created, displays a form and uses the information to create the user in the database. However, what is happening is that the $_POST variables are being tested (i.e. if(isset(...)) ), and an error message is displayed before the user has inputted any information.

Here is my code:
function __construct() {
$this->displayForm();
$this->name = $_POST["setup_fullname"];

if(count(str_split($_POST["setup_usr"], 1)) > 4 && usrIsFree($_POST["setup_usr"])) {
$this->username = $_POST["setup_usr"];
print($this->username);
} else {
echo '<script type="text/javascript">alert("Invalid Username! Username may be taken or is under the character limit.")</script>';
unset($_POST['setup_sbmt']);
$this->displayForm();
}

if(count(str_split($_POST["setup_pwd"], 1)) > 4) {
$this->password = md5($_POST["setup_pwd"]) + saltify($this->username);
} else {
echo '<script type="text/javascript">alert("Invalid Password")</script>';
unset($_POST['setup_sbmt']);
$this->displayForm();
}

if(isset($_POST['kmli'])) { $this->keepSession = true; } else { $this->keepSession = false; }

}
}
By the end of it I get 2 JScript messages saying ("invalid password/username") and the form is displayed 3 times.
Thanks in advance :)
- James
 
I don't think you fully understand how PHP works or what it's for.

This code isn't running in your browser. It can't be "paused" while you're interacting with the page, because by the time you see the page it's already finished.

A PHP script runs on the web server. It generates an HTML document that's then sent to the user's web browser. All the user sees is that generated HTML -- the PHP code is not sent to the user's browser. It's already done its job and finished by the time the user sees anything.
 
Back
Top