--- nfo/php/libs/com.newsblob.phphtmllib/form/FormProcessor.inc 2003/09/20 00:18:43 1.3
+++ nfo/php/libs/com.newsblob.phphtmllib/form/FormProcessor.inc 2004/05/06 16:27:22 1.4
@@ -2,7 +2,7 @@
/**
* This file contains the FormProcessor class.
*
- * $Id: FormProcessor.inc,v 1.3 2003/09/20 00:18:43 jonen Exp $
+ * $Id: FormProcessor.inc,v 1.4 2004/05/06 16:27:22 jonen Exp $
*
* @author Walter A. Boring IV
* @author Suren Markossian
@@ -146,15 +146,7 @@
* doing the form processing
*/
function _process_form() {
- //let the form build the FormElement objects
- //that will be used by the form
- $this->_form_content->form_init_elements();
-
- //first we need to
- if (!@$_REQUEST[FORM_VISITED]) {
- $this->_form_content->form_init_data();
- }
-
+ $this->_init_form_content();
//we only need to process the form
//if it has been visited. Otherwise
@@ -163,11 +155,16 @@
$this->_set_action();
//let see if this was a confirmation page.
- if ( !empty($_REQUEST[FORM_CONFIRM]) && $_REQUEST[FORM_CONFIRM] == 1 ) {
- //looks like this was a submit on a
- //confirmation page. we don't need
- //to do form field validation.
- $this->_confirmed = TRUE;
+ if ( !empty($_REQUEST[FORM_CONFIRM]) ) {
+ if ($_REQUEST[FORM_CONFIRM] == 1) {
+ //looks like this was a submit on a
+ //confirmation page. we don't need
+ //to do form field validation.
+ $this->_confirmed = TRUE;
+ } else {
+ //looks like the confirmation was aborted.
+ xxx("aborted");
+ }
}
//now do the validation
@@ -227,6 +224,16 @@
* confirmation page is rendered
*/
function _pre_confirm() {
+
+ 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
+ //them before confirmation has been accepted.
+ $this->_form_content->_pre_confirm();
+ }
+
+ //call the user defineable FormContent pre_confirm.
return $this->_form_content->pre_confirm();
}
@@ -637,12 +644,93 @@
/**
+ * Set the onsubmit attribute to the form
+ * NOTE: The FormContent child can automatically
+ * set this value depending on the FormElement
+ * children it contains.
+ *
+ * @param string
+ * @return none
+ */
+ function set_onsubmit($js) {
+ $this->_form_attributes["onsubmit"] = $js;
+ }
+
+ /**
+ * Gets the current value of the form tag's
+ * onsubmit value
+ *
+ * @return string
+ */
+ function get_onsubmit() {
+ return $this->_form_attributes["onsubmit"];
+ }
+
+
+ //************************************//
+ //* Some Private methods *//
+ //************************************//
+
+ /**
+ * This method initializes the FormContent
+ * during processing.
+ *
+ * @return none
+ */
+ function _init_form_content() {
+ //let the form build the FormElement objects
+ //that will be used by the form
+ $this->_form_content->form_init_elements();
+
+ //first we need to
+ if (!@$_REQUEST[FORM_VISITED]) {
+ $this->_form_content->form_init_data();
+ }
+
+ //see if the form content has a child of the
+ //FEFile element, so we can automatically
+ //add the enctype to the form tag attribute
+ if ($this->_form_content->_has_file_element) {
+ $this->set_form_enctype("multipart/form-data");
+ }
+ }
+
+
+ /**
* this function builds the FORMtag object
* and its attributes.
*
* @return FORMtag object.
*/
function _build_form_tag() {
+ //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 (strlen($this->_form_content->_form_on_submit) > 0) {
+ $set = TRUE;
+ $this->set_onsubmit( $this->get_onsubmit().$this->_form_content->_form_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 (strlen($this->_form_content->_form_on_submit) > 0) {
+ $set = TRUE;
+ $this->set_onsubmit( $this->get_onsubmit().$this->_form_content->_form_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) {
+ if (strlen($this->_form_content->_form_on_submit) > 0) {
+ $set = TRUE;
+ $this->set_onsubmit( $this->get_onsubmit().$this->_form_content->_form_on_submit );
+ }
+ }
+ }
+
$form_attrs = array();
foreach( $this->_form_attributes as $name => $value) {
if ($value) {
@@ -660,21 +748,12 @@
function _add_confirm_data() {
$keys = array_keys( $this->_form_content->_elements );
foreach( $keys as $key ) {
- $element_name = $this->_form_content->_elements[$key]->get_element_name();
- $values = $this->_form_content->_elements[$key]->get_value();
- if (is_array($values)) {
- foreach($values as $value) {
- $this->_form->add( form_hidden($element_name, $value) );
- }
- } else {
- $this->_form->add( form_hidden($element_name, $values) );
-
- }
+ $this->_form->add($this->_form_content->_elements[$key]->get_confirm_element());
}
$keys = array_keys( $this->_form_content->_hidden_elements );
foreach( $keys as $key ) {
- $this->_form->add( $this->_form_content->_hidden_elements[$key]->get_element() );
+ $this->_form->add( $this->_form_content->_hidden_elements[$key]->get_confirm_element() );
}
}