<?php
//////////////////////////////////////////////////////////////////////////////////////////////////
require_once('mvcinput.php');
define ( 'ADD' , true );
define ( 'REWRITE' , false );
class FormController {
/**
* Required Values
*
* @var string $name
* @var string $title
*/
public $name;
public $header;
/**
* Optional Values
*
* @var string $info
*/
private $info;
/**
* System Values
*
* @var string $errors
*/
private $errors;
/**
* $items - array with form items
*
* @var unknown_type
*/
private $items = array();
/**
* Model and View for the input
*
* @var object $model
* @var object $view
*/
private $model;
private $view;
function __construct( $name = 'form' , $header = '' ) {
/********************************/
$this->name = $name;
$this->header = $header;
/********************************/
$this->error = false;
$this->result = false;
/********************************/
$name = 'form';
$model_name = $name . 'Model';
$view_name = $name . 'View';
/********************************/
$this->model = new $model_name();
$this->view = new $view_name();
}
private function GetData(){
/***********************************************/
$data['name'] = $this->name;
$data['header'] = $this->header;
$data['info'] = $this->info;
$data['errors'] = $this->errors;
$data['items'] = $this->items;
return $data;
}
function Make() {
$data = $this->GetData();
// даннÑе оÑпÑавленÑ
if ( $_POST['do'] == 'register_go' ) {
$this->model->Validate( $this->GetData() );
}
return $this->view->Make( $this->GetData() );
}
function AddItem( $input ){
$this->items[$input->name] = &$input;
}
/**
* Set info for the form
*
* add values:
* ADD - add the info
* REWRITE - rewrite form info
*
* @param string $info
* @param mixed $add
*/
function SetInfo( $info , $add = false ){
$info = nl2br( $info );
if ( $add ){
$this->info = $this->info . $info;
}
else {
$this->info = $info;
}
}
/**
* Echo input returned by make function
*
*/
function Display(){
echo $this->Make();
}
} // class Controller
//////////////////////////////////////////////////////////////////////////////////////////////////
class FormView {
/**
* Makes the the form
*
* @param string header
* @param string body
* @param string info
* @param string errors
*/
static function Make( $data ) {
/****************************
data array
****************************/
$name = $data['name'];
$header = $data['header'];
/***************************/
$info = $data['info'];
$items = $data['items'];
$validated = $data['validated'];
/***************************/
$errors = '';
$body = '';
/***************************/
foreach ( $items as $item ){
$body .= '
<li>
' . $item->Make() .'
</li>
';
if ( $error = $item->GetErrorMessage() ){
$errors .= $error . "<br/>\n";
}
}
/****************************
<p>aragraphs with info
****************************/
if ( $header ){
$header = '<h3>' . $header . '</h3>' . "\n";
}
if ( $info ){
$info = '<p class="info">' . "\n\t" . $info . '</p>' . "\n";
}
if ( $errors ){
$errors = '<p class="errors">' . "\n\t" . $errors . '</p>' . "\n";
}
if ( $body ){
$body = '<ul id="fieldlist">' . "\n\t" . $body . "\n" . '</ul>' . "\n";
}
return '
<fieldset id="' . $name . '">
' . $header . '
<form action="" method="post" enctype="multipart/form-data">
<input type="hidden" name="do" value="register_go" />
' . $info
. $errors
. $body . '
<span class="hide">ÐÐ¾Ð»Ñ Ð¾ÑмеÑеннÑе звездоÑкой( * ) обÑзаÑелÑÐ½Ñ Ð´Ð»Ñ Ð·Ð°Ð¿Ð¾Ð»Ð½ÐµÐ½Ð¸Ñ.</span>
<div class="button"><input type="submit" name="submit" value="ÐаÑегиÑÑÑиÑоваÑÑÑÑ" /></div>
</form>
</fieldset>
';
}
} // class View
//////////////////////////////////////////////////////////////////////////////////////////////////
class FormModel {
public $data;
function __construct() {
$this->data = false;
}
function Validate( $data ) {
$items = $data['items'];
foreach ( $items as $item ){
$item->Validate();
}
}
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru" lang="ru">
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="style.css" title="base" />
<script type="text/javascript" src="../jQuery/jquery.js"></script>
<script type="text/javascript" src="../jQuery/roundCorners.jQuery.js"></script>
<style>
label {
color: #66f;
margin: 0px 0px 6px 0px;
width:30%;
border: 2px ridge #669;
background-color: #ffc;
clear: none;
margin: 0px 10% 0px 20%;
}
label.normal{
border-color: yellow;
}
label.warn{
border-color: red;
}
label.good{
border-color: green;
}
input{
border: 2px ridge #669;
background: #69f;
color: #ffc;
font-weight: bold;
margin: 0px 20% 0px 10%;
width: 30%;
clear: none;
}
.button input {
background-color: #99f;
border: 2px ridge black;
width: 40%;
margin: 0px 30% 0px 30%;
}
</style>
<?
/****************************
Creating form and its elements
****************************/
$form = new FormController( 'register_msg' , 'РегиÑÑÑаÑиÑ' );
$form->SetInfo(
'Ðогин и паÑÐ¾Ð»Ñ Ð´Ð¾Ð»Ð¶Ð½Ñ ÑодеÑжаÑÑ ÑолÑко лаÑинÑкие бÑÐºÐ²Ñ Ð¸ ÑиÑÑÑ.
Ðлина логина - до 15 Ñимволов, паÑÐ¾Ð»Ñ - до 20 Ñимволов.
ÐÐ¾Ð»Ñ Ð»Ð¾Ð³Ð¸Ð½, паÑÐ¾Ð»Ñ Ð¸ капÑа обÑзаÑелÑÐ½Ñ Ðº заполнениÑ, E-Mail опÑионалÑно.' );
$login = new InputController('login','Ðогин');
$login->SetRegExpPattern('/\d/i');
$login->SetRequired ( REQUIRED );
$password = new InputController('password','ÐаÑолÑ','password');
$password->SetRequired ( REQUIRED );
$email = new InputController('email','EMail');
$email->SetRegExpPattern('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])*(\.([a-z0-9])([-a-z0-9_-])([a-z0-9])+)*$/i');
$form->AddItem( $login );
$form->AddItem( $password );
$form->AddItem( $email );
$form->Display();
echo '<script type="text/javascript">$(\'.normal\').roundCorners();</script>';
function CapitalsToUnderscore( $string ){
$string = (string)$string;
$string = preg_replace( '/([A-Z])/e' , '_.strtolower($1)' , $string);
if ( $string[0] == '_' ){
$string = substr( $string , 1 );
}
return $string;
}
echo CapitalsToUnderscore( 'RandOmlYCapitaliZEDstringOo' );