jeffshead
July 31st, 2011, 04:07 PM
Hi all,
I'm new to CodeGuru and to PHP and Smarty for that matter. I'll try to keep this as short as I can.
I have a website that uses Smarty templates and I want to create a new web page that includes a "contact us" form which utilizes a PHP form script that I bought. The script is actually a suite in that it generates the forms based on the fields you want in your form and it contains the script that processes submissions, send emails and inserts the data into a database.
Basically, I cant figure out how to convert the PHP, from the form, to Smarty. I've been searching Google and playing around with the page for days but I cant get it to work so I'm hoping someone on here can lend a hand.
The Smarty templating system used on this website works by having a .php page and a .tpl page with the same name (e.g., testpage.php and testpage.tpl.). All of the PHP is supposed to go in the PHP page and the Smarty page is just supposed to be a template with variables and HTML.
Below is a PHP form page that I generated using the form generator I purchased. What you see below is a whole page that can be uploaded to a website and be used as is but I need to incorporate it into a Smarty template page.
<?php
/* BEGIN - SECTION 1 */
//require_once(dirname(__FILE__) . "/../../FORMfields.php");
require_once($_SERVER["DOCUMENT_ROOT"] . "/FORMfields/FORMfields.php"); // Absolute path
//$GLOBALS["FF_GLOBALS_VERBOSE"] = true; // For debugging purposes
//$GLOBALS["FF_GLOBALS_SEND_EMAILS"] = false; // For debugging purposes
// ---------- FORM PROPERTIES - START ----------
// NOTE: Only changes made to the form properties and structure
// (not actions) of the form can be reloaded into FORMgen.
define("FF_SLEEP", 4);
define("FF_FORM_NAME", "contact_us");
define("FF_FORM_TITLE", htmlspecialchars("Contact Us"));
define("FF_STYLE_FILE", FF_ROOT_URL . "/styles/defaultRightLabels.css");
define("FF_SHOW_W3C_VALIDATOR", false);
define("FF_DISPLAY_CONFIRMATION", true); // Note: Static form layout is not compatible with the confirmation screen.
define("FF_DISPLAY_THANK_YOU_PAGE", true);
define("FF_INSERT_INTO_DB", true);
define("FF_SEND_FORM_EMAIL1", true);
define("FF_FORM_EMAIL1_TO", "SiteAdministrator@mysite.com");
define("FF_FORM_EMAIL1_TO_FIELDS", "");
define("FF_FORM_EMAIL1_FROM", ""); // Note: You cannot specify a FF_FORM_EMAIL1_FROM and FF_FORM_EMAIL1_FROM_FIELD!
define("FF_FORM_EMAIL1_FROM_FIELD", "email");
define("FF_FORM_EMAIL1_SUBJECT", "Contact Us Submission");
define("FF_FORM_EMAIL1_MESSAGE_HEADER", "");
define("FF_FORM_EMAIL1_MESSAGE_FOOTER", "");
define("FF_FORM_EMAIL1_USE_HTML", true);
define("FF_FORM_EMAIL1_SEND_FORM_DATA", true);
define("FF_SEND_FORM_EMAIL2", false);
define("FF_FORM_EMAIL2_TO", "");
define("FF_FORM_EMAIL2_TO_FIELDS", "");
define("FF_FORM_EMAIL2_FROM", ""); // Note: You cannot specify both a FF_FORM_EMAIL2_FROM and FF_FORM_EMAIL2_FROM_FIELD!
define("FF_FORM_EMAIL2_FROM_FIELD", "");
define("FF_FORM_EMAIL2_SUBJECT", "Contact Us Submission");
define("FF_FORM_EMAIL2_MESSAGE_HEADER", "");
define("FF_FORM_EMAIL2_MESSAGE_FOOTER", "");
define("FF_FORM_EMAIL2_USE_HTML", true);
define("FF_FORM_EMAIL2_SEND_FORM_DATA", true);
$GLOBALS["FF_CANCEL_URL"] = "http://www.mysite.com";
$GLOBALS["FF_DONE_URL"] = "http://www.mysite.com";
$GLOBALS["FF_DEFAULTS"] = array(
"name" => "{\$user->user_info.user_displayname}",
"email" => "{\$user->user_info.user_email}"
);
// ---------- FORM PROPERTIES - END ----------
// ---------- FORM STRUCTURE - START ----------
$ffForm = new FfForm();
$ffForm->addField(new SessionVerificationField());
$ffForm->addField(new TimestampField("Timestamp"));
$ffForm->addField(new IpAddressField("IP Address"));
$ffForm->addField(new PersonNameField("name", "Name", FORM_FIELD_REQUIRED));
$ffForm->addField(new EmailAddrField("email", "Email Address", FORM_FIELD_REQUIRED));
$ffForm->addField(new TextField("subject", "Subject", FORM_FIELD_REQUIRED, 200, 1, 63));
$ffForm->addField(new TextAreaField("message", "Message", FORM_FIELD_REQUIRED, 1000, 1, 10, 60));
$ffForm->addField(new ImageVerificationField("Image Verification"));
$ffForm->addField(new SubmitField("ff_submit", "Submit"));
$ffForm->addField(new SubmitField("ff_clear", "Clear"));
$ffForm->addField(new SubmitField("ff_cancel", "Cancel"));
// ---------- FORM STRUCTURE - END ----------
// ---------- FORM ACTIONS - START ----------
class SubmitButtonListener extends FfButtonListener
{
function onClick(&$ffForm)
{
if ($ffForm->checkValues()) {
// CONFIRMATION OPERATION:
$ffForm->setEditable(false);
$ffForm->setEditableFields(array("ff_back", "ff_confirm"), true);
$ffForm->setHiddenFields(array("ff_back", "ff_confirm"), false);
$GLOBALS["action"] = FF_CONFIRM;
}
}
}
class ConfirmButtonListener extends FfButtonListener
{
function onClick(&$ffForm)
{
//echo "CONFIRM<hr/>";
if ($ffForm->checkValues()) {
// SUBMIT OPERATION:
$GLOBALS["action"] = FF_DONE;
// Send an email?
if (FF_SEND_FORM_EMAIL1)
{
$formEmail1To = FF_FORM_EMAIL1_TO;
// Add the to addresses which were entered by the user
$formEmail1ToFields = split(",", FF_FORM_EMAIL1_TO_FIELDS);
foreach($formEmail1ToFields as $fieldName) {
if (!empty($fieldName))
$formEmail1To .= "," . $ffForm->getValue($fieldName);
}
// Was the address specified or are we loading from a field name?
$formEmail1From = FF_FORM_EMAIL1_FROM;
if (!FormField::isBlank(FF_FORM_EMAIL1_FROM_FIELD)) {
$formEmail1From = $ffForm->getValue(FF_FORM_EMAIL1_FROM_FIELD);
}
$formEmail1Cc = null;
$formEmail1Bcc = null;
$formEmail1Subject = FF_FORM_EMAIL1_SUBJECT;
$formEmail1MsgHeader = FF_FORM_EMAIL1_MESSAGE_HEADER; // The text that preceeds the field values
$formEmail1MsgFooter = FF_FORM_EMAIL1_MESSAGE_FOOTER; // The text that follows the field values
$formEmail1CssFile = null; // If you don't like the defaulted CSS styles, you can include another style sheet.
$formEmail1UseHtml = FF_FORM_EMAIL1_USE_HTML; // Use false for text emails
$formEmail1SendFormData = FF_FORM_EMAIL1_SEND_FORM_DATA; // Use false to not send form data
$formEmail1SendFormUploads = true; // Use false to not attach files uploaded from the form
if (!$formEmail1UseHtml) { // Convert the line of text to multiple lines?
$formEmail1MsgHeader = str_replace("<br/>", "\n", $formEmail1MsgHeader);
$formEmail1MsgFooter = str_replace("<br/>", "\n", $formEmail1MsgFooter);
}
// You can include extra attachments by populating an array as follows.
// Note: All UploadFields are automatically attached to the email.
$formEmail1Attachments = null;
//$formEmail1Attachments[0] = array(dirname(__FILE__) . "/../calendar.gif", "calendar.gif");
$ffForm->email($formEmail1To, $formEmail1Subject, $formEmail1From,
$formEmail1Cc, $formEmail1Bcc, $formEmail1MsgHeader,
$formEmail1MsgFooter, $formEmail1Attachments, $formEmail1UseHtml,
$formEmail1CssFile, $formEmail1SendFormData, $formEmail1SendFormUploads);
}
// Send a second email?
if (FF_SEND_FORM_EMAIL2)
{
$formEmail2To = FF_FORM_EMAIL2_TO;
// Add the to addresses which were entered by the user
$formEmail2ToFields = split(",", FF_FORM_EMAIL2_TO_FIELDS);
foreach($formEmail2ToFields as $fieldName) {
if (!empty($fieldName))
$formEmail2To .= "," . $ffForm->getValue($fieldName);
}
$formEmail2From = FF_FORM_EMAIL2_FROM;
if (!FormField::isBlank(FF_FORM_EMAIL2_FROM_FIELD)) {
$formEmail2From = $ffForm->getValue(FF_FORM_EMAIL2_FROM_FIELD);
}
$formEmail2Cc = null;
$formEmail2Bcc = null;
$formEmail2Subject = FF_FORM_EMAIL2_SUBJECT;
$formEmail2MsgHeader = FF_FORM_EMAIL2_MESSAGE_HEADER; // The text that preceeds the field values
$formEmail2MsgFooter = FF_FORM_EMAIL2_MESSAGE_FOOTER; // The text that follows the field values
$formEmail2CssFile = null; // If you don't like the defaulted CSS styles, you can include another style sheet.
$formEmail2UseHtml = FF_FORM_EMAIL2_USE_HTML; // Use false for text emails
$formEmail2SendFormData = FF_FORM_EMAIL2_SEND_FORM_DATA; // Use false to not send form data
$formEmail2SendFormUploads = true; // Use false to not attach files uploaded from the form
if (!$formEmail2UseHtml) { // Convert the line of text to multiple lines?
$formEmail2MsgHeader = str_replace("<br/>", "\n", $formEmail2MsgHeader);
$formEmail2MsgFooter = str_replace("<br/>", "\n", $formEmail2MsgFooter);
}
// You can include extra attachments by populating an array as follows.
// Note: All UploadFields are automatically attached to the email.
$formEmail2Attachments = null;
//$formEmail2Attachments[0] = array(dirname(__FILE__) . "/../calendar.gif", "calendar.gif");
$ffForm->email($formEmail2To, $formEmail2Subject, $formEmail2From,
$formEmail2Cc, $formEmail2Bcc, $formEmail2MsgHeader,
$formEmail2MsgFooter, $formEmail2Attachments, $formEmail2UseHtml,
$formEmail2CssFile, $formEmail2SendFormData, $formEmail2SendFormUploads);
}
if (FF_INSERT_INTO_DB) {
$ffForm->addField(new DateTimeField("ff_inserted_on", "Inserted On", FORM_FIELD_REQUIRED, null));
$ffForm->formFields["ff_inserted_on"]->getCurrentDateTime();
$ffForm->insertValuesIntoDb(FF_FORM_NAME);
}
if (!FF_DISPLAY_THANK_YOU_PAGE) {
header("Location: " . $GLOBALS["FF_DONE_URL"]);
}
}
}
}
if ($ffForm->fieldExists("ff_submit")) {
// Does the submit button submit the data or confirm the data?
if (FF_DISPLAY_CONFIRMATION)
$ffForm->formFields["ff_submit"]->addButtonListener(new SubmitButtonListener());
else
$ffForm->formFields["ff_submit"]->addButtonListener(new ConfirmButtonListener());
}
if ($ffForm->fieldExists("ff_clear")) {
$ffForm->formFields["ff_clear"]->addButtonListener(new FfClearButtonListener());
}
class CancelButtonListener extends FfButtonListener
{
function onClick(&$ffForm)
{
// CANCEL OPERATION:
header("Location: " . $GLOBALS["FF_CANCEL_URL"]);
}
}
if ($ffForm->fieldExists("ff_cancel")) {
$ffForm->formFields["ff_cancel"]->addButtonListener(new CancelButtonListener());
}
$ffForm->addField(new SubmitField("ff_back", "<" . FfLH::t("Back")));
$confirmButton = new SubmitField("ff_confirm", FfLH::t("Confirm") . ">");
$confirmButton->addButtonListener(new ConfirmButtonListener());
$ffForm->addField($confirmButton);
class FormListener extends FfFormListener
{
function onNoClicks(&$ffForm)
{
// DEFAULT OPERATION:
// If necessary, convert the default values to multiple lines
if (sizeof($GLOBALS["FF_DEFAULTS"]) > 0) {
foreach ($GLOBALS["FF_DEFAULTS"] as $i=>$globalValue) {
$GLOBALS["FF_DEFAULTS"][$i] = str_replace("<br/>", "\n", $globalValue);
}
}
$ffForm->loadDbValues($GLOBALS["FF_DEFAULTS"]);
// Enter other default values here. Example:
//$ffForm->setValue("name", "John");
}
}
$ffForm->addFormListener(new FormListener());
define("FF_ENTER", 1);
define("FF_CONFIRM", 2);
define("FF_DONE", 3);
$GLOBALS["action"] = FF_ENTER;
$ffForm->setHiddenFields(array("ff_back", "ff_confirm"), true);
$ffForm->process();
// ---------- FORM ACTIONS - END ----------
/* END - SECTION 1 */
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo FF_FORM_TITLE ?></title>
<?php /* BEGIN - SECTION 2 */ ?>
<?php require_once(FF_SRC . "/FfIncludes.php"); ?>
<?php if ($GLOBALS["action"] == FF_DONE) { ?>
<meta http-equiv="Refresh" content="<?php echo FF_SLEEP ?>; url=<?php echo $GLOBALS["FF_DONE_URL"] ?>">
<?php } ?>
<style type="text/css">
/* Sometimes it is useful to specify a label width */
/*label.notValid, label.isValid, label.disabled, label.display {
width: 150px;
}*/
</style>
<?php /* END - SECTION 2 */ ?>
</head>
<body onload="setFocus();" class="FORMfields">
<?php /* BEGIN - SECTION 3 */ ?>
<div class="ffForm">
<a name="ffStart"></a>
<?php
// For debugging:
// print_r($_REQUEST);
// echo $ffForm->__toString();
?>
<form name="<?php echo $ffForm->getFormName() ?>" action="#ffStart" method="post" enctype="multipart/form-data">
<?php echo FfMenuHelper::getSectionTitleHeader(FF_FORM_TITLE) ?>
<?php if ($GLOBALS["action"] == FF_DONE) { ?>
<br />
<div class="ffConfirmation">
<?php echo FfLH::t("Thank you for your submission.") ?>
</div>
<div class="ffRedirectNote">
<a href="<?php echo $GLOBALS["FF_DONE_URL"] ?>"><?php echo (FfLH::t("Please click here if your browser does not redirect in") . " " . FF_SLEEP . " " . FfLH::t("seconds") . ".") ?></a>
</div>
<br />
<?php } else {
if ($GLOBALS["action"] == FF_CONFIRM) {
?>
<h3 class="FORMfields">
<?php echo FfLH::t("Please confirm that the following data is correct:") ?>
</h3>
<?php
} else {
?>
<div style="text-align:right;margin-bottom:10px;">
<span class="required">*</span><span class="help" style="padding-left:0px;font-size:9px;"> - <?php echo FfLH::t("required") ?></span>
</div>
<?php
}
echo $ffForm->getTableTag();
} ?>
<?php echo FfMenuHelper::getSectionTitleFooter() ?>
<div style="text-align:right;">
<a href="<?php echo FF_ROOT_URL ?>" target="_blank"><img class="ffTinyLogo" alt="FORMfields, The Premiere Web Framework." src="http://www.mysite.com/FORMfields/images/blank.gif"/></a><a style="font: normal normal normal 9px verdana,sans-serif;" href="http://www.formfields.com" target="_blank">Form Generated by FORMgen</a>
</div>
<?php if (FF_SHOW_W3C_VALIDATOR) { ?>
<div>
<a href="http://validator.w3.org/check?uri=referer"><img border="0" src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a>
<a href="http://jigsaw.w3.org/css-validator/check/referer"><img style="border:0;width:88px;height:31px" src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!" /></a>
</div>
<?php } ?>
</form>
</div>
<?php /* END - SECTION 3 */ ?>
</body>
</html>
You will notice that the above generated page is divided into three sections. It's set up this way to make it easy to integrate the form with any standard PHP page. Section 1 gets added to the very top of a given webpage, section 2 gets added to the head and section 3 gets added to the body of a page.
continued in second post (too long for a single post)
I'm new to CodeGuru and to PHP and Smarty for that matter. I'll try to keep this as short as I can.
I have a website that uses Smarty templates and I want to create a new web page that includes a "contact us" form which utilizes a PHP form script that I bought. The script is actually a suite in that it generates the forms based on the fields you want in your form and it contains the script that processes submissions, send emails and inserts the data into a database.
Basically, I cant figure out how to convert the PHP, from the form, to Smarty. I've been searching Google and playing around with the page for days but I cant get it to work so I'm hoping someone on here can lend a hand.
The Smarty templating system used on this website works by having a .php page and a .tpl page with the same name (e.g., testpage.php and testpage.tpl.). All of the PHP is supposed to go in the PHP page and the Smarty page is just supposed to be a template with variables and HTML.
Below is a PHP form page that I generated using the form generator I purchased. What you see below is a whole page that can be uploaded to a website and be used as is but I need to incorporate it into a Smarty template page.
<?php
/* BEGIN - SECTION 1 */
//require_once(dirname(__FILE__) . "/../../FORMfields.php");
require_once($_SERVER["DOCUMENT_ROOT"] . "/FORMfields/FORMfields.php"); // Absolute path
//$GLOBALS["FF_GLOBALS_VERBOSE"] = true; // For debugging purposes
//$GLOBALS["FF_GLOBALS_SEND_EMAILS"] = false; // For debugging purposes
// ---------- FORM PROPERTIES - START ----------
// NOTE: Only changes made to the form properties and structure
// (not actions) of the form can be reloaded into FORMgen.
define("FF_SLEEP", 4);
define("FF_FORM_NAME", "contact_us");
define("FF_FORM_TITLE", htmlspecialchars("Contact Us"));
define("FF_STYLE_FILE", FF_ROOT_URL . "/styles/defaultRightLabels.css");
define("FF_SHOW_W3C_VALIDATOR", false);
define("FF_DISPLAY_CONFIRMATION", true); // Note: Static form layout is not compatible with the confirmation screen.
define("FF_DISPLAY_THANK_YOU_PAGE", true);
define("FF_INSERT_INTO_DB", true);
define("FF_SEND_FORM_EMAIL1", true);
define("FF_FORM_EMAIL1_TO", "SiteAdministrator@mysite.com");
define("FF_FORM_EMAIL1_TO_FIELDS", "");
define("FF_FORM_EMAIL1_FROM", ""); // Note: You cannot specify a FF_FORM_EMAIL1_FROM and FF_FORM_EMAIL1_FROM_FIELD!
define("FF_FORM_EMAIL1_FROM_FIELD", "email");
define("FF_FORM_EMAIL1_SUBJECT", "Contact Us Submission");
define("FF_FORM_EMAIL1_MESSAGE_HEADER", "");
define("FF_FORM_EMAIL1_MESSAGE_FOOTER", "");
define("FF_FORM_EMAIL1_USE_HTML", true);
define("FF_FORM_EMAIL1_SEND_FORM_DATA", true);
define("FF_SEND_FORM_EMAIL2", false);
define("FF_FORM_EMAIL2_TO", "");
define("FF_FORM_EMAIL2_TO_FIELDS", "");
define("FF_FORM_EMAIL2_FROM", ""); // Note: You cannot specify both a FF_FORM_EMAIL2_FROM and FF_FORM_EMAIL2_FROM_FIELD!
define("FF_FORM_EMAIL2_FROM_FIELD", "");
define("FF_FORM_EMAIL2_SUBJECT", "Contact Us Submission");
define("FF_FORM_EMAIL2_MESSAGE_HEADER", "");
define("FF_FORM_EMAIL2_MESSAGE_FOOTER", "");
define("FF_FORM_EMAIL2_USE_HTML", true);
define("FF_FORM_EMAIL2_SEND_FORM_DATA", true);
$GLOBALS["FF_CANCEL_URL"] = "http://www.mysite.com";
$GLOBALS["FF_DONE_URL"] = "http://www.mysite.com";
$GLOBALS["FF_DEFAULTS"] = array(
"name" => "{\$user->user_info.user_displayname}",
"email" => "{\$user->user_info.user_email}"
);
// ---------- FORM PROPERTIES - END ----------
// ---------- FORM STRUCTURE - START ----------
$ffForm = new FfForm();
$ffForm->addField(new SessionVerificationField());
$ffForm->addField(new TimestampField("Timestamp"));
$ffForm->addField(new IpAddressField("IP Address"));
$ffForm->addField(new PersonNameField("name", "Name", FORM_FIELD_REQUIRED));
$ffForm->addField(new EmailAddrField("email", "Email Address", FORM_FIELD_REQUIRED));
$ffForm->addField(new TextField("subject", "Subject", FORM_FIELD_REQUIRED, 200, 1, 63));
$ffForm->addField(new TextAreaField("message", "Message", FORM_FIELD_REQUIRED, 1000, 1, 10, 60));
$ffForm->addField(new ImageVerificationField("Image Verification"));
$ffForm->addField(new SubmitField("ff_submit", "Submit"));
$ffForm->addField(new SubmitField("ff_clear", "Clear"));
$ffForm->addField(new SubmitField("ff_cancel", "Cancel"));
// ---------- FORM STRUCTURE - END ----------
// ---------- FORM ACTIONS - START ----------
class SubmitButtonListener extends FfButtonListener
{
function onClick(&$ffForm)
{
if ($ffForm->checkValues()) {
// CONFIRMATION OPERATION:
$ffForm->setEditable(false);
$ffForm->setEditableFields(array("ff_back", "ff_confirm"), true);
$ffForm->setHiddenFields(array("ff_back", "ff_confirm"), false);
$GLOBALS["action"] = FF_CONFIRM;
}
}
}
class ConfirmButtonListener extends FfButtonListener
{
function onClick(&$ffForm)
{
//echo "CONFIRM<hr/>";
if ($ffForm->checkValues()) {
// SUBMIT OPERATION:
$GLOBALS["action"] = FF_DONE;
// Send an email?
if (FF_SEND_FORM_EMAIL1)
{
$formEmail1To = FF_FORM_EMAIL1_TO;
// Add the to addresses which were entered by the user
$formEmail1ToFields = split(",", FF_FORM_EMAIL1_TO_FIELDS);
foreach($formEmail1ToFields as $fieldName) {
if (!empty($fieldName))
$formEmail1To .= "," . $ffForm->getValue($fieldName);
}
// Was the address specified or are we loading from a field name?
$formEmail1From = FF_FORM_EMAIL1_FROM;
if (!FormField::isBlank(FF_FORM_EMAIL1_FROM_FIELD)) {
$formEmail1From = $ffForm->getValue(FF_FORM_EMAIL1_FROM_FIELD);
}
$formEmail1Cc = null;
$formEmail1Bcc = null;
$formEmail1Subject = FF_FORM_EMAIL1_SUBJECT;
$formEmail1MsgHeader = FF_FORM_EMAIL1_MESSAGE_HEADER; // The text that preceeds the field values
$formEmail1MsgFooter = FF_FORM_EMAIL1_MESSAGE_FOOTER; // The text that follows the field values
$formEmail1CssFile = null; // If you don't like the defaulted CSS styles, you can include another style sheet.
$formEmail1UseHtml = FF_FORM_EMAIL1_USE_HTML; // Use false for text emails
$formEmail1SendFormData = FF_FORM_EMAIL1_SEND_FORM_DATA; // Use false to not send form data
$formEmail1SendFormUploads = true; // Use false to not attach files uploaded from the form
if (!$formEmail1UseHtml) { // Convert the line of text to multiple lines?
$formEmail1MsgHeader = str_replace("<br/>", "\n", $formEmail1MsgHeader);
$formEmail1MsgFooter = str_replace("<br/>", "\n", $formEmail1MsgFooter);
}
// You can include extra attachments by populating an array as follows.
// Note: All UploadFields are automatically attached to the email.
$formEmail1Attachments = null;
//$formEmail1Attachments[0] = array(dirname(__FILE__) . "/../calendar.gif", "calendar.gif");
$ffForm->email($formEmail1To, $formEmail1Subject, $formEmail1From,
$formEmail1Cc, $formEmail1Bcc, $formEmail1MsgHeader,
$formEmail1MsgFooter, $formEmail1Attachments, $formEmail1UseHtml,
$formEmail1CssFile, $formEmail1SendFormData, $formEmail1SendFormUploads);
}
// Send a second email?
if (FF_SEND_FORM_EMAIL2)
{
$formEmail2To = FF_FORM_EMAIL2_TO;
// Add the to addresses which were entered by the user
$formEmail2ToFields = split(",", FF_FORM_EMAIL2_TO_FIELDS);
foreach($formEmail2ToFields as $fieldName) {
if (!empty($fieldName))
$formEmail2To .= "," . $ffForm->getValue($fieldName);
}
$formEmail2From = FF_FORM_EMAIL2_FROM;
if (!FormField::isBlank(FF_FORM_EMAIL2_FROM_FIELD)) {
$formEmail2From = $ffForm->getValue(FF_FORM_EMAIL2_FROM_FIELD);
}
$formEmail2Cc = null;
$formEmail2Bcc = null;
$formEmail2Subject = FF_FORM_EMAIL2_SUBJECT;
$formEmail2MsgHeader = FF_FORM_EMAIL2_MESSAGE_HEADER; // The text that preceeds the field values
$formEmail2MsgFooter = FF_FORM_EMAIL2_MESSAGE_FOOTER; // The text that follows the field values
$formEmail2CssFile = null; // If you don't like the defaulted CSS styles, you can include another style sheet.
$formEmail2UseHtml = FF_FORM_EMAIL2_USE_HTML; // Use false for text emails
$formEmail2SendFormData = FF_FORM_EMAIL2_SEND_FORM_DATA; // Use false to not send form data
$formEmail2SendFormUploads = true; // Use false to not attach files uploaded from the form
if (!$formEmail2UseHtml) { // Convert the line of text to multiple lines?
$formEmail2MsgHeader = str_replace("<br/>", "\n", $formEmail2MsgHeader);
$formEmail2MsgFooter = str_replace("<br/>", "\n", $formEmail2MsgFooter);
}
// You can include extra attachments by populating an array as follows.
// Note: All UploadFields are automatically attached to the email.
$formEmail2Attachments = null;
//$formEmail2Attachments[0] = array(dirname(__FILE__) . "/../calendar.gif", "calendar.gif");
$ffForm->email($formEmail2To, $formEmail2Subject, $formEmail2From,
$formEmail2Cc, $formEmail2Bcc, $formEmail2MsgHeader,
$formEmail2MsgFooter, $formEmail2Attachments, $formEmail2UseHtml,
$formEmail2CssFile, $formEmail2SendFormData, $formEmail2SendFormUploads);
}
if (FF_INSERT_INTO_DB) {
$ffForm->addField(new DateTimeField("ff_inserted_on", "Inserted On", FORM_FIELD_REQUIRED, null));
$ffForm->formFields["ff_inserted_on"]->getCurrentDateTime();
$ffForm->insertValuesIntoDb(FF_FORM_NAME);
}
if (!FF_DISPLAY_THANK_YOU_PAGE) {
header("Location: " . $GLOBALS["FF_DONE_URL"]);
}
}
}
}
if ($ffForm->fieldExists("ff_submit")) {
// Does the submit button submit the data or confirm the data?
if (FF_DISPLAY_CONFIRMATION)
$ffForm->formFields["ff_submit"]->addButtonListener(new SubmitButtonListener());
else
$ffForm->formFields["ff_submit"]->addButtonListener(new ConfirmButtonListener());
}
if ($ffForm->fieldExists("ff_clear")) {
$ffForm->formFields["ff_clear"]->addButtonListener(new FfClearButtonListener());
}
class CancelButtonListener extends FfButtonListener
{
function onClick(&$ffForm)
{
// CANCEL OPERATION:
header("Location: " . $GLOBALS["FF_CANCEL_URL"]);
}
}
if ($ffForm->fieldExists("ff_cancel")) {
$ffForm->formFields["ff_cancel"]->addButtonListener(new CancelButtonListener());
}
$ffForm->addField(new SubmitField("ff_back", "<" . FfLH::t("Back")));
$confirmButton = new SubmitField("ff_confirm", FfLH::t("Confirm") . ">");
$confirmButton->addButtonListener(new ConfirmButtonListener());
$ffForm->addField($confirmButton);
class FormListener extends FfFormListener
{
function onNoClicks(&$ffForm)
{
// DEFAULT OPERATION:
// If necessary, convert the default values to multiple lines
if (sizeof($GLOBALS["FF_DEFAULTS"]) > 0) {
foreach ($GLOBALS["FF_DEFAULTS"] as $i=>$globalValue) {
$GLOBALS["FF_DEFAULTS"][$i] = str_replace("<br/>", "\n", $globalValue);
}
}
$ffForm->loadDbValues($GLOBALS["FF_DEFAULTS"]);
// Enter other default values here. Example:
//$ffForm->setValue("name", "John");
}
}
$ffForm->addFormListener(new FormListener());
define("FF_ENTER", 1);
define("FF_CONFIRM", 2);
define("FF_DONE", 3);
$GLOBALS["action"] = FF_ENTER;
$ffForm->setHiddenFields(array("ff_back", "ff_confirm"), true);
$ffForm->process();
// ---------- FORM ACTIONS - END ----------
/* END - SECTION 1 */
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo FF_FORM_TITLE ?></title>
<?php /* BEGIN - SECTION 2 */ ?>
<?php require_once(FF_SRC . "/FfIncludes.php"); ?>
<?php if ($GLOBALS["action"] == FF_DONE) { ?>
<meta http-equiv="Refresh" content="<?php echo FF_SLEEP ?>; url=<?php echo $GLOBALS["FF_DONE_URL"] ?>">
<?php } ?>
<style type="text/css">
/* Sometimes it is useful to specify a label width */
/*label.notValid, label.isValid, label.disabled, label.display {
width: 150px;
}*/
</style>
<?php /* END - SECTION 2 */ ?>
</head>
<body onload="setFocus();" class="FORMfields">
<?php /* BEGIN - SECTION 3 */ ?>
<div class="ffForm">
<a name="ffStart"></a>
<?php
// For debugging:
// print_r($_REQUEST);
// echo $ffForm->__toString();
?>
<form name="<?php echo $ffForm->getFormName() ?>" action="#ffStart" method="post" enctype="multipart/form-data">
<?php echo FfMenuHelper::getSectionTitleHeader(FF_FORM_TITLE) ?>
<?php if ($GLOBALS["action"] == FF_DONE) { ?>
<br />
<div class="ffConfirmation">
<?php echo FfLH::t("Thank you for your submission.") ?>
</div>
<div class="ffRedirectNote">
<a href="<?php echo $GLOBALS["FF_DONE_URL"] ?>"><?php echo (FfLH::t("Please click here if your browser does not redirect in") . " " . FF_SLEEP . " " . FfLH::t("seconds") . ".") ?></a>
</div>
<br />
<?php } else {
if ($GLOBALS["action"] == FF_CONFIRM) {
?>
<h3 class="FORMfields">
<?php echo FfLH::t("Please confirm that the following data is correct:") ?>
</h3>
<?php
} else {
?>
<div style="text-align:right;margin-bottom:10px;">
<span class="required">*</span><span class="help" style="padding-left:0px;font-size:9px;"> - <?php echo FfLH::t("required") ?></span>
</div>
<?php
}
echo $ffForm->getTableTag();
} ?>
<?php echo FfMenuHelper::getSectionTitleFooter() ?>
<div style="text-align:right;">
<a href="<?php echo FF_ROOT_URL ?>" target="_blank"><img class="ffTinyLogo" alt="FORMfields, The Premiere Web Framework." src="http://www.mysite.com/FORMfields/images/blank.gif"/></a><a style="font: normal normal normal 9px verdana,sans-serif;" href="http://www.formfields.com" target="_blank">Form Generated by FORMgen</a>
</div>
<?php if (FF_SHOW_W3C_VALIDATOR) { ?>
<div>
<a href="http://validator.w3.org/check?uri=referer"><img border="0" src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a>
<a href="http://jigsaw.w3.org/css-validator/check/referer"><img style="border:0;width:88px;height:31px" src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!" /></a>
</div>
<?php } ?>
</form>
</div>
<?php /* END - SECTION 3 */ ?>
</body>
</html>
You will notice that the above generated page is divided into three sections. It's set up this way to make it easy to integrate the form with any standard PHP page. Section 1 gets added to the very top of a given webpage, section 2 gets added to the head and section 3 gets added to the body of a page.
continued in second post (too long for a single post)