So I'am about to write a class for an encryption application with mcrypt().
So my first method is just about the validation of the submitted values from a HTML-Formular of my index.php-page.
The funny thing is that when I call the method fetch_data() it affects my CSS-code of the index.php-File.
Does anybody know why is this? Thanks a lot!
Here are the files:
crypt_lib.php:
- Code: Select all
class MyCrypt{
private $error = array();
private $data = array();
public function fetch_data($data,$error){
if(isset($_POST['input'])){
if(!isset($_POST['txt_file']) && empty($_POST['txt_file'])) {
$error[] = "Please enter the name of your textfile.";
}
if(!empty($_POST['passwd']) && !empty($_POST['passwdvalid']) &&
($_POST['passwd'] != $_POST['passwdvalid'])) {
$error[] = "The passwords do not coincide";
}
elseif(!isset($_POST['passwd']) && empty($_POST['passwd'])) {
$error[] = "Please enter a password.";
}
elseif(!isset($_POST['passwdvalid']) && empty($_POST['passwdvalid'])) {
$error[] = "Please repete the password.";
}
else{
$data[] = $_POST['txt_file'];
$data[] = $_POST['passwd'];
}
$this->error = $error;
return $error;
}
}
}
index.php:
- Code: Select all
<?php
error_reporting(E_ALL);
ini_set('display_errors',true);
session_start();
include "lib/crypt_lib.php";
$crt = new MyCrypt;
$crt->fetch_data();
?>
<!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" xml:lang="de" lang="de">
<head>
<title>Titel</title>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
<meta name="description" content="" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="generator" content="Webocton - Scriptly (www.scriptly.de)" />
<link rel="stylesheet" href="../registrierung/css/main.css" type="text/css"/>
<link href="favicon.ico" type="image/x-icon" rel="shortcut icon" />
</head>
<body>
<div id="wrapper">
<div id="left_column">
</div>
<div id="right_column">
<form name="" action="#" method="POST" enctype="text/html">
<div style="margin-left:30px;"><h3>Generate Textfile:</h3> </div>
<table cellspacing="0">
<tr class="required">
<th scope="row">Name of the text file:</th>
<td> <input name="txt_file" type="text" size="15" maxlength="30"/></td>
</tr>
</table><br/><br />
<div style="margin-left:30px;"><h3>password:</h3> </div>
<table cellspacing="0">
<tr class="required">
<th scope="row">password:</th>
<td> <input name="passwd" type="text" size="15" maxlength="30"/></td>
</tr>
<tr class="required">
<th scope="row">Please confirm password:</th>
<td> <input name="passwdvalid" type="text" size="15" maxlength="30"/></td>
</tr>
</table>
<div style="margin-left: 200px; margin-top: 0px;">
<input type="submit" name="output" value="send"/></div>
</form>
<br/><div style="font-size: 0.8em; margin-left:20px;"><b><?php foreach($crt->error as $v){
echo $v.'br/'; } ?></b></div>
</div>
</div>
</body>
</html>

