Skip to content

Instantly share code, notes, and snippets.

Created September 4, 2009 21:10
Show Gist options
  • Save anonymous/181134 to your computer and use it in GitHub Desktop.
Save anonymous/181134 to your computer and use it in GitHub Desktop.
<?php
function exception_handler($exception) {
echo $exception->getMessage();
}
set_exception_handler('exception_handler');
?>
<?php
class Form {
function validateName($name){
if(!$name || strlen($name) == 0){
throw new Exception("Feltet er tomt!");
return 1;
}
else
return 0;
}
function validateEntry($entry){
if(!$entry || strlen($entry) == 0){
return 1;
}
else
return 0;
}
}
$form = new Form();
?>
<?php
include("include/form.php");
include("include/errors.php");
class Process {
function Add($name, $entry){
global $form;
$validateName = $form->validateName($name);
$validateEntry = $form->validateEntry($entry);
$Validate = $validateName+$validateEntry;
if($Validate == 0){
//$sql->AddToDB($subName, $subAge, $subCity);
header("Location: index.php");
}
else {
header("Location: opret.php");
}
}
}
$process = new Process();
if(isset($_POST['Add'])){
$process->Add($_POST['name'], $_POST['entry']);
}
?>
<form action="" method="post">
<label for="name">Navn: </label><br />
<input type="text" name="name" id="name" /><br />
<label for="entry">Indlæg: </label><br />
<textarea name="entry" id="entry" cols="30" rows="9"></textarea>
<input type="hidden" name="Add" value="1" />
<br /><br />
<input type="submit" value="Send!" />
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment