|
|
PHP Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
if(isset($_POST['add_entry_submit'])) { $entry_data = array( 'entry_name' => $_POST['entry_name'], 'entry_text' => $_POST['entry_text'], 'entry_mail' => $_POST['entry_mail'], 'entry_website' => $_POST['entry_website'], 'entry_IP' => $_SERVER['REMOTE_ADDR'] ); if(empty($_POST['entry_name'])) { $information = true; $information_text = $language['ADD_ENTRY_EMPTY_ENTRY_NAME']; $information_type = 'error'; } elseif(empty($_POST['entry_text'])) { $information = true; $information_text = $language['ADD_ENTRY_EMPTY_ENTRY_TEXT']; $information_type = 'error'; } else { $entry = new entry($entry_data['entry_name'], $entry_data['entry_text'], $entry_data['entry_mail'], $entry_data['entry_website'], $entry_data['entry_IP']); $addEntry = $entry->addEntry(); if($addEntry == true) { $information = true; $information_text = $language['ADD_ENTRY_SUCCESSFULL']; $information_type = 'accept'; $entry_added = true; } else { $information = true; $information_text = $language['ADD_ENTRY_ERROR']; $information_type = 'error'; } } $smarty->assign($entry_data); } |
|
|
PHP Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
public function set_entry_name($entry_name) { if($entry_name != "") // evtl. kann man dann auch hier weitere Überprüfungen reinbringen ob der Wert Wörter enthält die nicht drinstehen dürfen (Badlist oder sowas in der Richtung...) { $this->entry_name = $entry_name; } else { $anonym_entries_allowed = $db->getData("SELECT 'setting_value' FROM ".TABLE_PREFIX."settings WHERE 'setting_name' = 'anonym_entries_allowed"); if($anonym_entries_allowed[0] == 1) { $this->entry_name = $language['ENTRY_NAME_ANONYM']; } else { return false; } } } |
|
|
PHP Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
public function __construct($entry_name, $entry_text, $entry_mail, $entry_website, $entry_IP) { $this->set_entry_name($entry_name); $this->set_entry_mail($entry_mail); $this->set_entry_website($entry_website); $this->set_entry_text($entry_text); $this->set_entry_IP($entry_IP); } public function getResult() { return $this->result; } public function checkValue($select, $from, $where, $wheredata) { global $sql; return $sql->getData("SELECT ".$select." FROM ".TABLE_PREFIX."".$from." WHERE ".$where." = '".$wheredata."'"); } public function validation($attribut, $value, $select, $from, $where, $wheredata, $replace_value) { if($value != "") { $this->$attribut = $value; } elseif($select == '' && $from == '' && $where == '' && $wheredata == '') { $this->result = false; } else{ $this->validation_value = $this->checkValue($select, $from, $where, $wheredata); if($this->validation_value[0] == 1) { $this->$attribut = $replace_value; $this->result = true; } else { $this->result = false; } } } public function set_entry_name($entry_name) { global $language; $this->validation('entry_name', $entry_name, 'setting_value', 'settings', 'setting_name', 'anonym_entry_allowed', $language['ENTRY_NAME_ANONYM']); } |


|
|
PHP Quellcode |
1 2 3 4 5 6 7 8 9 10 11 |
<form method="post"> email: <input type="text" name="email" /><br/> password: <input type="password" name="password" /><br/> <input type="submit"> </form> <?php if(count($_POST)) { $user = new User($_POST); $user->save(); } ?> |
|
|
PHP Quellcode |
1 2 3 4 5 6 7 8 9 10 11 |
<form method="post"> email: <input type="text" name="email" /><br/> password: <input type="password" name="password" /><br/> <input type="submit"> </form> <?php if(count($_POST)) { $user = new User($_POST); $user->save(); } ?> |
|
|
PHP Quellcode |
1 |
throw new ValidateException('message'); |
This post has been edited 3 times, last edit by "Illidan" (Jan 31st 2010, 7:23pm)
|
|
PHP Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
|
|
|
PHP Quellcode |
1 2 3 4 5 6 7 8 9 10 11 |
if($this->data['entry_name'] == '') { if($check_anonym_name != 1) { throw new ValidateException('ANONYM_ENTRY_NOT_ALLOWED'); } else { throw new ValidateException('ANONYM_ENTRY_ALLOWED'); } } |
Vielen kann man erzählen und erzählen und sie machen es nicht.|
|
PHP Quellcode |
1 2 3 4 5 6 7 8 9 10 11 |
class User extends Model { public function save($override = null) { if($override !== null) { $this->data = array_merge($this->data, $override); } if(empty($this->email)) { $this->email = 'unknown'; } parent::save(); } } |
Hm.. für meinen Geschmack nutzt damit zu viele Exceptions.
Vor allem klingt das für mich nicht schlüssig, dass eine Exception im Bedarfsfall noch weitere Exceptions schmeißt...
This post has been edited 1 times, last edit by "Illidan" (May 30th 2010, 4:17pm)