Tengo este formulario, pero al darle a enviar no pasa nada. No sé donde está el problema
Código PHP:
<?php
ob_start();
$self = htmlentities($_SERVER['PHP_SELF']);
?>
<?php
/*Filtering data*/
$clean = array();
$input_errors = array();
/*control state and collect data*/
$form_is_submitted = false;
$input_errors_detected = false;
$reg_status = false;
if (!empty($_POST['register'])) {
$form_is_submitted = true;
$makeHtml = trim($_POST['fullname']);
/*validate data*/
if(!empty($_POST['fullname'])) {
if (strlen($makeHtml)<=100 ) {
$clean['fullname'] = htmlentities($makeHtml);
}
else {
$input_errors['fullname'] = 'Enter your name, no longer than 100 characters';
$input_errors_detected = true;
}
}
else {
$input_errors['fullname'] = 'Please enter your name.';
$input_errors_detected = true;
}
$makeHtml = trim($_POST['email']);
if(!empty($_POST['email'])) {
if (filter_var($makeHtml,FILTER_VALIDATE_EMAIL)) {
$clean['email'] = htmlentities($makeHtml);
}
else {
$input_errors['email'] = 'Please enter a correct email address.';
$input_errors_detected = true;
}
}
else {
$input_errors['email'] = 'Please enter your email.';
$input_errors_detected = true;
}
$makeHtml = trim($_POST['user']);
if(!empty($_POST['user'])) {
if (strlen($makeHtml)<=30) {
$clean['user'] = htmlentities($makeHtml);
}
else {
$input_errors['user'] = 'Please enter a username, no longer than 30 characters.';
$input_errors_detected = true;
}
}
else {
$input_errors['user'] = 'Please enter your username.';
$input_errors_detected = true;
}
$makeHtml = $_POST['password'];
if(!empty($_POST['password'])) {
if (strlen($makeHtml)<=150) {
$clean['password'] = htmlentities($makeHtml);
}
else {
$input_errors['password'] = 'Please enter your password';
$input_errors_detected = true;
}
}
else {
$input_errors['password'] = 'Please enter your password.';
$input_errors_detected = true;
}
}
?>
<!-- Form -->
<form action="<?php echo $self; ?>" method="post">
<fieldset>
<?php
//Correcting errors
if ($form_is_submitted === true && $input_errors_detected !== false) {
echo '<p>Please correct the errors</p>';
foreach ($input_errors as $error) {
echo '<p>'.$error.'</p>';
}
} elseif ($form_is_submitted === true && $input_errors_detected === false) {
// Process data
$user = array();
$processing_errors = array();
$processing_errors_detected = false;
$username = $clean['user'];
$email = $clean['email'];
$handle = fopen('process.php', 'r');
while(!feof($handle)) {
$line[] = fgets($handle);
foreach($line as $details_string) {
$user_details_all[] = unserialize($details_string);
}
foreach($user_details_all as $user) {
if($username == $user['user']) {
$processing_errors_detected = true;
$processing_errors['user_repeat'] = 'Sorry, this name is already taken. Please insert a new one';
break;
}
}
foreach($user_details_all as $user) {
if($email == $user['email']) {
$processing_errors_detected = true;
$processing_errors['email_repeat'] = 'Sorry, that email is already taken. Please insert a new one';
break;
}
}
}
fclose($handle);
if ($form_is_submitted === true && $processing_errors_detected !== false) {
echo '<p>There are errors</p>';
foreach ($processing_errors as $error) {
echo '<p>'.$error.'</p>';
}
} elseif ($form_is_submitted === true && $processing_errors_detected === false) {
$user = $clean;
$details_string = serialize($user).PHP_EOL;
$result = file_put_contents('process.php', $details_string, FILE_APPEND);
if ($result === false) {
echo 'There is an error , please try again.';
} else {
foreach ($clean as $key => $details) {
$_SESSION[$key] = $details;
}
$reg_status = true;
header('Location: http://titan.dcs.bbk.ac.uk/~lvazqu01/p1fma/index.php?'.SID.'');
}
}
}
?>
<?php
if (!empty($clean['fullname'])) {
$name = htmlentities($clean['fullname']);
} else {
$name = '';
}
if (!empty($clean['email'])) {
$email = htmlentities($clean['email']);
} else {
$email = '';
}
if (!empty($clean['usern'])) {
$username = htmlentities($clean['user']);
} else {
$username = '';
}
?>
<div>
<label for="name">Full name:</label>
<input type="text" name="fullname" id="name"/>
</div>
<div>
<label for="mail">Email address</label>
<input type="text" name="email" id="mail"/>
</div>
<div>
<label for="username">Username</label>
<input type="text" name="user" id="username"/>
</div>
<div>
<label for="pass">Password:</label>
<input type="password" name="password" id="pass"/>
</div>
<input type="submit"
name="contactsubmit"
value="register" />
</fieldset>
</form>