<?php
// See bottom of this file for notes on changes,
// items to take care of, etc.
// Production as of 3/2/12
// ffaFormParser
// 1) Set vars
// 2) Get hidden fields, custom form data in formAdd
// 3) Parse form data
// 4) If empty or there are errors
// a) Save the data, insure that we have a valid 'unique' key
// b) paint form with existing data
// 5) Otherwise, write the data to the proper tables
// a) To what degree does the process depend on the type of field? 's', 'n', etc.
// public function retPreparedType($type) in msi.database
// 6) Then notify
// a) Either send generic notification or send data
// b) Data sent per table or generically
class ffaFormParser {
//
//
// $post is $_POST, the only required arg: $debug is optional
public function __construct($post, $debug = FALSE) {
//
// Initial display of form? then $_POST does not exist
if (!($post)) { header( 'Location: ' . 'index.html'); }
//
//
require_once('constants.inc.php');
//
//
require_once('class.msi_database.php');
require_once('class.ffaFormData.php');
require_once('class.ffaMathCaptcha.php');
require_once('class.ffaFormValidator.php');
//
//
$opts = array();
//
$this->debug = $debug;
// ...but...
if (isset($post['debug'])) {
$this->debug = $post['debug'];
}
//
//
$this->chkSetOptions($opts);
//
//
$this->rawData = $post; // No clean up yet...
//
//
// Now get the info necessary to validate the input fields, which,
// before we found out which database we were dealing with, was
// impossible to properly do. (We needed to know what kind of
// data is supposed to be returned from the fields, and that
// information is in a table in the chosen database.)
//
// Open a database connection
$this->db = new msi_database(DBNAME, $opts);
//
//
// Look at what got returned, first time, AND CLEAN THE $_POST INPUT
$this->cleanDataAndParseHiddenFields();
//
//
// Does the form want custom post-processing?
// (We cannot check this until this point since $this->formName will
// not exist until the previous call is made...)
$this->chkCustomPost();
//
//
//
// Now instantiate the data handling class for forms
$this->frmDat = new ffaFormData($this);
// **********************************************************************
// NOTE that we do not call chkSetOptions from ffaFormData class. Why not??
// **********************************************************************
//
// $this->empty would be made TRUE by this next call, where there is no user input
$this->valid = new ffaFormValidator();
//
//
// NOTE that it is only at this point that we deal with potential $_POST threat
//$this->db->prtObj($this->rawData);
//echo '<h4>Before:</h4>';
//$this->db->prtObj($this->rawData);
$this->rawData = $this->validateData($this->rawData);
//echo '<br><br><h4>After:</h4>';
//$this->db->prtObj($this->rawData);
//
// Store what we have, whether nothing, data with errors, or OK data
$this->frmDat->setDataAndErrors($this);
//
// And was the form submitted empty besides? Then either display home page
// or redisplay form with appropriate error message
if ($this->empty) {
if ($this->OnEmpty == '_:home') {
if (! $this->debug) {
// *********************************************
// index.html is hardcoded
// *********************************************
header( 'Location: ' . 'index.html');
exit();
}
}
}
//
// Do we have other errors besides?
if ((isset($this->errors)) && (is_array($this->errors)) && ($this->errors <> array())) {
// We need to repaint the form, with errors...
// Passing 'caller' through a form has mangled '.php' somewhat...
$a = str_ireplace('_php', '.php', $this->caller);
header( 'Location: ' . $a . '?unique=' . $this->unique );
exit();
}
else {
// If we have arrived here, then we have some data, which has no obvious errors:
// Write it into the requisite tables...
$this->writeFormData();
//
// ...and alert the media. Tell 'em about it:
$this->notifyOfFormData();
//
//
// Then clean up (delete unique, whatever)...
if (! $this->debug) {
$this->cleanUp();
}
//
//
// ...And do custom post-processing...
// Note that this may send the user to another site: PayPal, for example...
if ($this->formClass['Exists']) {
$this->doCustomPost();
}
else {
// *****************************************************
// Bye Bye
header( 'Location: ' . $this->FormAccepted);
exit();
}
//
}
//
} // end of function __construct
public function writeFormData() {
//
//
// *********************************************************
// This next call cycles back through a DB call.
// Do we need that overhead?
$this->frmDat->retExistingDataAndErrors($this);
// *********************************************************
//
// As a result of the previous call, $this->data is an array
// keyed by table and then field which stores everything we know
// about the data, including the hidden fields. What we need now
// is to establish the independent autoincrement key fields, then
// use values returned from the call to preparedFromArray_Insert
// which takes, as its args, the name of the table to which to write,
// an array of [field names= => [field values], such as we get from
// $this->data. Where the key field for that table is autoincrement
// and its value is NULL, preparedFrom[...] will return the key val
// for use in writing any dependent tables.
//
if (is_array($this->keyFields)) {
// Its pretty unlikely that we will get more than one key field per
// table, but nevertheless...
foreach ($this->keyFields as $tbl => $keyAr) {
foreach ($keyAr as $fld => $dependent) {
// $dependent is now a numerically indexed array which
// contains a list of [table][fld] elements referencing
// dependent tables and their key fields, linked of course
// to $tbl and $fld, such as
// "[0][CommentsQuestionsInfo] => ID_People"
//
// The next call will create/return a set of values in $this->autoInc.
// See the function itself for the straight skinny
$this->frmDat->setupAutoIncrementPreparedWrite(
$this, // us here
$tbl, // The independent table name
$fld, // Its autoincrement key field name
$this->data[$tbl], // An array particular to the indep table
// where field names index their values
$this->tables[$tbl]); // An array particular as above, where each
// field's characteristics are described
//
$retVal = $this->frmDat->doAutoIncrementPreparedWrite($this, $tbl, $fld);
//
if ($retVal) {
$this->data[$tbl][$fld] = $retVal;
}
//
for ($i = 0; $i < count($dependent); $i++) {
foreach ($dependent[$i] as $tblD => $fldD) {
// I can't imagine a situation where we would have more than
// one dependent field per dependent table...
$this->data[$tblD][$fldD] = $retVal;
$this->frmDat->setupPreparedWrite($this, $tblD,
$this->data[$tblD],
$this->tables[$tblD]);
$retVal = $
没有合适的资源?快使用搜索试试~ 我知道了~
PHP解析形式,面向对象.zip
共1个文件
php:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 171 浏览量
2023-03-10
10:04:22
上传
评论
收藏 8KB ZIP 举报
温馨提示
PHP解析形式,面向对象.zip
资源推荐
资源详情
资源评论
收起资源包目录
PHP解析形式,面向对象.zip (1个子文件)
PHP解析形式,面向对象
_class.ffaFormParser.php 27KB
A
共 1 条
- 1
资源评论
N201871643
- 粉丝: 908
- 资源: 2289
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功