Source for file Form.php
Documentation is available at Form.php
* A Framework for Creating and Using Complex Web Elements
* The purpose of this framework is to provide a library of high-level objects
* to facilitate common HTML coding tasks, such as menus, tables, and forms.
* The intent is to reduce repetitive HTML coding as much as possible, replacing
* it with a combination of configuration files and style sheets with
* standardized naming conventions.
* This framework is built on and requires the
* {@link http://framework.zend.com/ Zend Framework}.
* @author Lyle Frost <lfrost@cnz.com>
* @copyright Copyright (c) 2006-2007 Citadel Network <{@link http://www.citadelnetwork.com/}>
* @license http://www.citadelnetwork.com/license/cnzframework New BSD License
* @version $Id: Form.php 27 2007-07-19 18:47:54Z lfrost $
Zend_Loader::loadClass('Cnz_Html_Form_Abstract');
* This class automates the creation and display of a form. CSS form style
* names are standardized as follows:
* formLabel[-<i>formname</i>-<i>fieldname</i>]: div block containing a single form label
* formField[-<i>formname</i>-<i>fieldname</i>]: div block containing a single form field
* IDs are standardardized as:
* form[-<i>formname<i>-<i>fieldname</i>]
* form[-<i>formname<i>-<i>fieldname</i>]-<i>number</i>
* See demo at {@link http://cfdemo.cnz.com/}.
private $mailSubject = NULL;
private $method = 'post';
private $onSubmit = NULL;
private $submitMethod = NULL;
/* Getters/Setters ===================================================*/
/** @return string Action */
/** @return string Method */
/* Methods ===========================================================*/
* mailSubject Mail subject
* method Form method (get or post)
* onSubmit Form onsubmit value
* @param array $options Options
// Process configuration.
if (isset ($this->config->action)) $this->action = $this->config->action;
if (isset ($this->config->mailTo)) $this->mailTo = $this->config->mailTo;
if (isset ($this->config->mailSubject)) $this->mailSubject = $this->config->mailSubject;
if (isset ($this->config->mailBcc)) $this->mailBcc = $this->config->mailBcc;
if (isset ($this->config->method)) $this->method = $this->config->method;
if (isset ($this->config->onSubmit)) $this->onSubmit = $this->config->onSubmit;
* @param string $style Value for outermost style attribute
public function display($style = NULL)
echo $indent, '<div class = "', $this->genStyles(), '"';
if (!empty($style)) echo ' style = "', $style, '"';
echo $indent, '<form action = "', $this->action, '"';
if ($this->fileFlag) echo ' enctype = "', self::ENCTYPE_FILE, '"';
echo ' method = "', $this->method, '"';
if (!empty($this->onSubmit)) echo ' onsubmit = "', $this->onSubmit, '"';
echo $indent, '<div class = "formButton"><button type = "submit">Send</button></div>', "\n";
echo $indent, '</form>', "\n";
echo $indent, '</div>', "\n";
* Display submitted data (for debugging).
* @param boolean $rawFlag Display as raw data, else filter and format.
if ($this->method == 'post') $data = $_POST;
* Submit the form by mail.
* If there is a field named <kbd>email</kbd>, this is automatically
* @return boolean Success
Zend_Loader::loadClass('Zend_Mail');
if ($this->method == 'post') $data = $_POST;
if (empty($this->mailTo))
$mailBody = 'Received from ' . $_SERVER['REMOTE_ADDR'] . ' using ' . $_SERVER['HTTP_USER_AGENT'] . "\n\n" . $mailBody;
if (isset ($data['email']) && !empty($data['email'])) $mail->setFrom($data['email']);
else $mail->setFrom($this->mailTo);
$mail->addTo($this->mailTo);
if (!empty($this->mailBcc)) $mail->addBcc($this->mailBcc);
$mail->setSubject($this->mailSubject);
$mail->setBodyText($mailBody);
Zend_Loader::loadClass('Zend_Mime');
foreach ($_FILES as $name => $upload)
if ($upload['error'] == UPLOAD_ERR_OK)
Cnz_Html::getLogger()->err(__METHOD__ . '[' . __LINE__ . '] ' . 'Attempt to attach file that was not uploaded. File name = ' . $upload['tmp_name'] . '.');
$fp = fopen($upload['tmp_name'], 'r');
Cnz_Html::getLogger()->err(__METHOD__ . '[' . __LINE__ . '] ' . 'Attempt to attach file that was not uploaded. File name = ' . $upload['tmp_name'] . '.');
echo '<p>Error attaching file ', $upload['name'], '.</p>', "\n\n";
$at = new Zend_Mime_Part($fp);
$at->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
$at->encoding = Zend_Mime::ENCODING_8BIT;
$at->type = Zend_Mime::TYPE_OCTETSTREAM;
$at->filename = $upload['name'];
$mail->addAttachment($at);
catch (Zend_Exception $e)
Cnz_Html::getLogger()->err(__METHOD__ . '[' . __LINE__ . '] ' . 'Exception from ' . get_class($e) . ': ' . $e->getMessage() . '.');
|