Ñâåðíóòûé òåêñò
<?php
class ControllerQuestions
{
public $username;
public $email;
public $website;
public $phone;
public $country;
public $city;
public $sex;
public $year;
public $month;
public $day;
public $title;
public $message;
public function __construct()
{
$this->username = $this->escape($_POST['username']);
$this->email = $this->escape($_POST['email']);
$this->website = $this->escape($_POST['website']);
$this->phone = $this->escape($_POST['phone']);
$this->country = $this->escape($_POST['country']);
$this->city = $this->escape($_POST['city']);
$this->sex = $this->escape($_POST['sex']);
$this->year = (int)trim($_POST['year']);
$this->day = (int)trim($_POST['day']);
$this->title = $this->escape($_POST['title']);
$this->month = $this->escape($_POST['month']);
$this->message = $this->escape($_POST['message']);
$this->errors = array();
}
public function validate()
{
if(empty($this->username) || empty($this->email) || empty($this->website)
|| empty($this->phone) || empty($this->country) || empty($this->sex)
|| empty($this->year) || empty($this->month) || empty($this->day)
|| empty($this->title) || empty($this->message))
{
$this->errors[] .= 'Âñå ïîëÿ äîëæíû áûòü çàïîëíåíû';
}
if((mb_strlen($this->username)<4) || (mb_strlen($this->title)<4) || (mb_strlen($this->message)<4))
{
$this->errors[] = 'Íåêîòîðûå ïîëÿ ñëèøêîì êîðîòêèå. Óâåëè÷üòå, ïîæàëóéñòà, êîëè÷åñòâî ñèìâîëîâ';
}
if(!preg_match("/[A-Za-z0-9]+@[a-zA-Z]+[A-Za-z0-9]+.[A-Za-z]/", $this->email))
{
$this->errors[] = 'Email àäðåñ íå êîððåêòíûé';
}
if(preg_match("/(http:\/\/)/", $this->website))
{
$this->errors[] = 'Íàçâàíèå ñàéòà äîëæíî áûòü áåç http://';
}
if(!preg_match("/[A-Za-z0-9]+[.]{1}[A-Za-z0-9]+/", $this->website))
{
$this->errors[] = 'Íå êîððåêòíûé àäðåñ ñàéòà';
}
if(!preg_match("/([(]+)[0-9]{1,4}([)]+)(\-|\s)[0-9]{1,4}(\-|\s)[0-9]+/", $this->phone))
{
$this->errors[] = 'Íå êîððåêòíûé òåëåôîí, ïðèìåð: (ÕÕÕÕ)-ÕÕÕ-ÕÕÕÕ';
}
return count($this->errors) ? 0 : 1;
}
public function sendAd()
{
$this->birth = '';
$this->birth .= $this->year;
$this->birth .= $this->month;
$this->birth .= $this->day;
$query = ("INSERT INTO `OopAd`(`title`, `username`, `email`, `website`, `phone`, `message`, `country`, `city`, `sex`, `birth`)
VALUES ('".$this->title."', '".$this->username."', '".$this->email."', '".$this->website."', '".$this->phone."',
'".$this->message."', '".$this->country."', '".$this->city."', '".$this->sex."', '".$this->birth."')");
$mysql = mysql_query($query) or die(mysql_error());
}
public function escape($var) {
return mysql_real_escape_string(trim(($var)));
}
public function showErrors()
{
foreach($this->errors as $key=>$errors)
echo $errors . '<br />';
return count($this->errors) ? 0 : 1;
}
}
?>
Õîòåë óçíàòü, êàê äàëüøå èäòè ïî ñõåìå ìâö? Ðàáîòà ñ íàñëåäîâàíèåì? Áåç øàáëîíèçàòîðà, ïðîñòî âûâîä èíôû.