Jump to content

Forms, cleared on failed


Eggzorcist

Recommended Posts

This is the very first time this is happening to me. I have a register form and when I click register and there is an error it clears the entire form but I've never gotten this before...

I think it might be in my xhtml code.

 

 

<?php 
require_once('functions.php');
?>
<!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=UTF-8" />
<title>Register</title>
</head>

<body>
<div id="error_message">
<?php if(isset($_POST['register'])){

register_user($_POST['email'], $_POST['pw1'], $_POST['pw2'], $_POST['firstname'], $_POST['lastname']);

} ?>
</div>
<form id="register_user" method="post" action="<?php $_SERVER['PHP_SELF'];  ?>">
<label>E-mail:
<input type="text" name="email" id="email" />*
</label>
<label>Password:
<input type="password" name="pw1" id="pw1" />*
</label>
<label>Comfirm:
<input type="password" name="pw2" id="pw2" />*
</label>
<br><br>
<label>First Name:
<input type="text" name="firstname" id="firstname" />*
</label>
<label>Last Name: 
<input type="text" name="lastname" id="lastname" />*
</label>
<br><br>
<input type="submit" id="register" name="register" value="Register" />
</form>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/182052-forms-cleared-on-failed/
Share on other sites

Your code should be like the following the value has to be assigned

 

<?php 
require_once('functions.php');
?>
<!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=UTF-8" />
<title>Register</title>
</head>

<body>
<div id="error_message">


<?php 
$email = isset($_POST['email']) ? $_POST['email'] : '';
$pw1 = isset($_POST['pw1']) ? $_POST['pw1'] : '';
$pw2 = isset($_POST['pw2']) ? $_POST['pw2'] : '';
$firstname = isset($_POST['firstname']) ? $_POST['firstname'] : '';
$lastname = isset($_POST['lastname']) ? $_POST['lastname'] : '';


if(isset($_POST['register'])){

register_user($email, $pw1, $pw2, $firstname, $lastname);

} 
?>
</div>
<form id="register_user" method="post" action="<?php $_SERVER['PHP_SELF'];  ?>">
<label>E-mail:
<input type="text" name="email" id="email" value="<?php echo $email; ?>"/>*
</label>
<label>Password:
<input type="password" name="pw1" id="pw1"  value="<?php echo $pw1; ?>"/>*
</label>
<label>Comfirm:
<input type="password" name="pw2" id="pw2"  value="<?php echo $pw2; ?>"/>*
</label>
<br><br>
<label>First Name:
<input type="text" name="firstname" id="firstname"  value="<?php echo $firstname; ?>"/>*
</label>
<label>Last Name:
<input type="text" name="lastname" id="lastname"  value="<?php echo $lastname; ?>"/>*
</label>
<br><br>
<input type="submit" id="register" name="register" value="Register" />
</form>
</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.