--- nfo/php/libs/com.newsblob.phphtmllib/form/FormProcessor.inc 2004/05/06 16:27:22 1.4
+++ nfo/php/libs/com.newsblob.phphtmllib/form/FormProcessor.inc 2005/08/11 14:09:26 1.5
@@ -2,9 +2,9 @@
/**
* This file contains the FormProcessor class.
*
- * $Id: FormProcessor.inc,v 1.4 2004/05/06 16:27:22 jonen Exp $
+ * $Id: FormProcessor.inc,v 1.5 2005/08/11 14:09:26 jonen Exp $
*
- * @author Walter A. Boring IV
+ * @author Walter A. Boring IV
* @author Suren Markossian
* @package phpHtmlLib
* @subpackage FormProcessing
@@ -21,7 +21,7 @@
* This is the main engine for the processing
* of Forms. It builds the form tag, and calls
* the appropriate FormContent methods to build
- * the FormElement's and validation, as well as
+ * the FormElement's and validation, as well as
* backend processing to do the action after the
* data has been validated.
*
@@ -85,7 +85,7 @@
/**
* The form was processed and passed
- * the confirmation if any, and
+ * the confirmation if any, and
* it was successfull ?
*/
var $_confirmed_successfull = FALSE;
@@ -133,13 +133,14 @@
* form errors object that is to be
* used by this form.
*
- * You can override this method to
+ * You can override this method to
* use a different FormErrors object
* for localization.
*/
- function setup_validation() {
- $this->_FormValidation = new FormValidation( new FormErrors );
- }
+ function setup_validation() {
+ $this->_FormValidation =& FormValidation::singleton();
+ $this->_form_content->_set_validation_object($this->_FormValidation);
+ }
/**
* This method does the logic of
@@ -151,7 +152,8 @@
//we only need to process the form
//if it has been visited. Otherwise
//it just gets rendered.
- if (!empty($_REQUEST[FORM_VISITED]) && $_REQUEST[FORM_VISITED] == 1) {
+ if (!empty($_REQUEST[$this->_form_attributes['name'].FORM_VISITED]) &&
+ $_REQUEST[$this->_form_attributes['name'].FORM_VISITED] == 1) {
$this->_set_action();
//let see if this was a confirmation page.
@@ -167,40 +169,31 @@
}
}
- //now do the validation
- if (!$this->_confirmed) {
- //we haven't been confirmed, so we
- //need to validate the form.
- if ($this->can_validate()) {
- //looks like we should do validation
- $this->do_validation();
- }
- if (!$this->_has_errors) {
- //no errors were found
- if ($this->_form_content->has_confirm()) {
- //the form content has a confirmation
- //we need to process
- $this->_has_errors = !$this->_pre_confirm();
- } else {
- //make sure we don't have any backend errors
- $this->_has_errors = !$this->_form_content->form_backend_validation();
- if (!$this->_has_errors) {
- $this->_has_errors = !$this->_process_action();
- if (!$this->_has_errors) {
- $this->_set_confirmed_success(TRUE);
- }
- }
- }
- }
- } else {
+ if ($this->_form_content->has_confirm()) {
+ //the form content has a confirmation
+ //we need to process
+ $this->_has_errors = !$this->_pre_confirm();
+ }
+
+ //we haven't been confirmed, so we
+ //need to validate the form.
+ if ($this->can_validate()) {
+ //looks like we should do validation
+ $this->do_validation();
+ }
+ if (!$this->_has_errors) {
+ //no errors were found
//make sure we don't have any backend errors
$this->_has_errors = !$this->_form_content->form_backend_validation();
- if (!$this->_has_errors) {
+ if (!$this->_has_errors && (($this->_form_content->has_confirm()
+ && $this->_confirmed) || !$this->_form_content->has_confirm())) {
+ // process action only at the final stage
$this->_has_errors = !$this->_process_action();
+
if (!$this->_has_errors) {
$this->_set_confirmed_success(TRUE);
}
- }
+ }
}
}
}
@@ -219,7 +212,7 @@
}
/**
- * This method calls the FormContent
+ * This method calls the FormContent
* to let it do any data munging before the
* confirmation page is rendered
*/
@@ -228,7 +221,7 @@
if ($this->_form_content->_has_file_element) {
//we need to allow any/all of the file elements
//save the temp files during a confirmation.
- //if we don't, then the web server may delete
+ //if we don't, then the web server may delete
//them before confirmation has been accepted.
$this->_form_content->_pre_confirm();
}
@@ -246,9 +239,16 @@
function do_validation() {
$keys = array_keys( $this->_form_content->_elements );
foreach( $keys as $key ) {
- $valid = $this->_form_content->_elements[$key]->_do_validation($this->_FormValidation);
- if (!$valid) {
- $this->_has_errors = TRUE;
+ if (!$this->_form_content->_elements[$key]->is_disabled()) {
+ $valid = $this->_form_content->_elements[$key]->_do_validation($this->_FormValidation);
+ if (!$valid) {
+ $this->_has_errors = TRUE;
+ }
+ } else {
+ //detect disabled field hack attempts
+ if ($this->_form_content->_elements[$key]->has_error()) {
+ $this->_has_errors = TRUE;
+ }
}
}
}
@@ -265,14 +265,14 @@
return $this->render_error($indent_level, $output_debug);
} else {
//there are no errors!
- if (@$_REQUEST[FORM_VISITED] == 1) {
+ if (@$_REQUEST[$this->_form_attributes['name'] . FORM_VISITED] == 1) {
//looks like the form has been processed?
if ($this->_form_content->has_confirm() && !$this->_confirmed) {
return $this->render_confirm($indent_level, $output_debug);
} else {
//Looks like the action worked
$success = $this->_form_content->form_success();
-
+
if ($this->_form_success_render) {
return $this->render_form($indent_level, $output_debug,
$success);
@@ -338,7 +338,7 @@
} else {
return $this->_form->render($indent_level, $output_debug);
}
-
+
}
/**
@@ -384,7 +384,7 @@
* @return raw html
*/
function render_error( $indent_level, $output_debug) {
-
+
if ($this->_auto_show_errors) {
//Ok first lets build the error table
$wrapper = new DIVtag;
@@ -393,7 +393,7 @@
} else {
$wrapper = NULL;
}
-
+
return $this->render_form( $indent_level, $output_debug, $wrapper);
}
@@ -430,7 +430,7 @@
/**
* This is used to test to see if the form action
- * was processed succesfully.
+ * was processed succesfully.
* This is usefull for external entities to determine
* if the form was processed, and it was successfull.
*
@@ -455,7 +455,7 @@
* This sets the flag that tells this class
* to automatically call the form contents
* form errors and display it or not
- *
+ *
* @param boolean - show errors?
*/
function set_auto_error_display($flag=TRUE) {
@@ -495,7 +495,7 @@
/**
* This method returns an array of errors that
* happened in the form.
- *
+ *
* @return array
*/
function get_error_array() {
@@ -623,7 +623,7 @@
/**
- * This is used to set the action
+ * This is used to set the action
* submitted by the user
*
*/
@@ -648,7 +648,7 @@
* NOTE: The FormContent child can automatically
* set this value depending on the FormElement
* children it contains.
- *
+ *
* @param string
* @return none
*/
@@ -659,13 +659,26 @@
/**
* Gets the current value of the form tag's
* onsubmit value
- *
+ *
* @return string
*/
function get_onsubmit() {
return $this->_form_attributes["onsubmit"];
}
+ /**
+ * Set a random attribute on the form tag.
+ * You should know what you are doing as this
+ * might invalidate the output html with the
+ * W3C validator.
+ *
+ * @param string the key
+ * @param string the value
+ */
+ function set_form_attribute($key, $value) {
+ $this->_form_attributes[$key] = $value;
+ }
+
//************************************//
//* Some Private methods *//
@@ -674,7 +687,7 @@
/**
* This method initializes the FormContent
* during processing.
- *
+ *
* @return none
*/
function _init_form_content() {
@@ -683,7 +696,7 @@
$this->_form_content->form_init_elements();
//first we need to
- if (!@$_REQUEST[FORM_VISITED]) {
+ if (!@$_REQUEST[$this->_form_attributes['name'] . FORM_VISITED]) {
$this->_form_content->form_init_data();
}
@@ -692,7 +705,7 @@
//add the enctype to the form tag attribute
if ($this->_form_content->_has_file_element) {
$this->set_form_enctype("multipart/form-data");
- }
+ }
}
@@ -706,28 +719,28 @@
//see if we need to add the onsubmit attribute to the form
//this only needs to happen on the non-confirmation
//portion of the forms.
- if (!isset($_REQUEST[FORM_VISITED])) {
+ if (!isset($_REQUEST[$this->_form_attributes['name'] . FORM_VISITED])) {
if (strlen($this->_form_content->_form_on_submit) > 0) {
$set = TRUE;
- $this->set_onsubmit( $this->get_onsubmit().$this->_form_content->_form_on_submit );
+ $this->set_onsubmit( $this->get_onsubmit().$this->_form_content->_form_on_submit.$this->_form_content->_form_action_elements_on_submit );
}
} else {
//re-rendering the form and it has errors.
//we need the onsubmit if they have it.
- if ($_REQUEST[FORM_VISITED] && $this->_has_errors) {
+ if (isset($_REQUEST[$this->_form_attributes['name'] . FORM_VISITED]) && $this->_has_errors) {
if (strlen($this->_form_content->_form_on_submit) > 0) {
$set = TRUE;
- $this->set_onsubmit( $this->get_onsubmit().$this->_form_content->_form_on_submit );
+ $this->set_onsubmit($this->get_onsubmit().$this->_form_content->_form_on_submit.$this->_form_content->_form_action_elements_on_submit );
}
- }
-
- //form has been confirmed lets add it
- //in case we are showing the form again
- if (isset($_REQUEST[FORM_CONFIRM]) && $_REQUEST[FORM_CONFIRM] == 1) {
+ } else if (isset($_REQUEST[FORM_CONFIRM]) && $_REQUEST[FORM_CONFIRM] == 1) {
+ //form has been confirmed lets add it
+ //in case we are showing the form again
if (strlen($this->_form_content->_form_on_submit) > 0) {
$set = TRUE;
- $this->set_onsubmit( $this->get_onsubmit().$this->_form_content->_form_on_submit );
+ $this->set_onsubmit( $this->get_onsubmit().$this->_form_content->_form_on_submit.$this->_form_content->_form_action_elements_on_submit );
}
+ } else {
+ $this->set_onsubmit($this->_form_content->_form_action_elements_on_submit);
}
}
@@ -736,7 +749,7 @@
if ($value) {
$form_attrs[$name] = $value;
}
- }
+ }
$this->_form = new FORMtag( $form_attrs );
}
@@ -748,7 +761,10 @@
function _add_confirm_data() {
$keys = array_keys( $this->_form_content->_elements );
foreach( $keys as $key ) {
- $this->_form->add($this->_form_content->_elements[$key]->get_confirm_element());
+ //make sure the element isn't disabled.
+ if (!$this->_form_content->_elements[$key]->is_disabled()) {
+ $this->_form->add($this->_form_content->_elements[$key]->get_confirm_element());
+ }
}
$keys = array_keys( $this->_form_content->_hidden_elements );
@@ -779,10 +795,10 @@
*/
function __hidden_fields() {
$this->_form->add( form_hidden(FORM_ACTION),
- form_hidden(FORM_VISITED,1) );
+ form_hidden($this->_form_attributes['name'] . FORM_VISITED,1) );
if ($this->_form_content->has_confirm() && !$this->_confirmed) {
- if (@!$_REQUEST[FORM_VISITED] || $this->_has_errors) {
+ if (@!$_REQUEST[$this->_form_attributes['name'] . FORM_VISITED] || $this->_has_errors) {
$this->_form->add( form_hidden(FORM_CONFIRM, 0 ) );
} else {
$this->_form->add( form_hidden(FORM_CONFIRM, 1 ) );