public static function GetInstance($formname = false) { if (!isset(self::$instance) && $formname !== false) { $className = __CLASS__; self::$instance = new $className($formname); } return self::$instance; }
public function getCMSFields() { $fields = parent::getCMSFields(); $fields->addFieldToTab("Root.Main", new HTMLEditorField("RedirectText", "Text Explaining PayPal Redirect"), "Metadata"); if (permission::check('ADMIN')) { $fields->addFieldToTab("Root.PayPalSettings", new TextField("PayPalAccount", "PayPal Account (email address)")); } return $fields; }
public function getCMSFields() { $fields = parent::getCMSFields(); $fields->addFieldToTab("Root.MapDetails", new TextField("MapZoom", "Map Zoom Level (lower number = farther away)")); $fields->addFieldToTab("Root.MapDetails", new DropdownField("MapType", "Map Display Type", array("ROADMAP" => "Roadmap", "SATELLITE" => "Satellite", "HYBRID" => "Hybrid", "TERRAIN" => "Terrain"), "Roadmap")); $fields->addFieldToTab("Root.MapDetails", new TextField("MapAddress", "Address for Map")); $fields->addFieldToTab("Root.MapDetails", new CheckboxField("MapDirections", "Display Directions Widget?")); return $fields; }
function Save() { if ($this->_GetFileHandle()) { $data = array(); $this->_FlattenPost(); $rules = Config::GetInstance()->GetConfig('rules'); foreach ($rules as $field => $rule) { if (!isset($this->post[$field])) { // it could still be an uploaded file $notfound = true; foreach (FormPage::GetInstance()->uploads as $up) { if ($up['fieldname'] == $field) { $data[] = $up['storedname']; $notfound = false; break; } } if ($notfound) { $data[] = ''; } } else { if ($rule->fieldtype == 'date' && !empty($this->post[$field])) { $data[] = date(Config::GetInstance()->GetDateFormatByFieldname($field), $this->post[$field]); } else { if ($field == '_submitted_') { $data[] = Config::ApplyUserTimezone($this->post[$field]); } else { $data[] = $this->post[$field]; } } } } foreach (Config::GetInstance()->GetReservedFields() as $name) { if (isset($this->post[$name]) && $name == '_submitted_') { $data[] = Config::GetInstance()->ApplyUserTimezone($this->post[$name]); } else { if (isset($this->post[$name])) { $data[] = $this->post[$name]; } else { $data[] = ''; } } } fputcsv($this->fp, $data); fclose($this->fp); } else { $this->errors[] = array('err' => _T('Failed to record the data because the server is too busy or doesn\'t have write permission.')); } }
public function getCMSFields() { $fields = parent::getCMSFields(); $blocked_config = GridFieldConfig::create()->addComponents(new GridFieldToolbarHeader(), new GridFieldAddNewButton('toolbar-header-right'), new GridFieldSortableHeader(), new GridFieldDataColumns(), new GridFieldPaginator(10), new GridFieldEditButton(), new GridFieldDeleteAction(), new GridFieldDetailForm()); $fields->addFieldToTab('Root.AppointmentSettings', new GridField('BlockedAppointmentDates', 'Blocked Appointment Dates', $this->BlockedAppointmentDates(), $blocked_config)); $fields->addFieldToTab("Root.AppointmentSettings", new CheckboxField("BlockWeekends", "Block Weekends?")); $fields->addFieldToTab("Root.AppointmentSettings", new CheckboxSetField("BlockedWeekdays", "Block Weekdays", array(1 => 'Sunday', 2 => 'Monday', 3 => 'Tuesday', 4 => 'Wednesday', 5 => 'Thursday', 6 => 'Friday', 7 => 'Saturday'))); $fields->addFieldToTab('Root.AppointmentSettings', new NumericField('TimeStep', 'Time Step (in time selection)')); $fields->addFieldToTab("Root.AppointmentSettings", new DropdownField("OpenTime", "Opening Time", $this->TimeArray())); $fields->addFieldToTab("Root.AppointmentSettings", new DropdownField("CloseTime", "Closing Time", $this->TimeArray())); $fields->addFieldToTab("Root.AppointmentSettings", new TextField("AutoResponderSubject", "Auto-responder Subject")); $fields->addFieldToTab("Root.AppointmentSettings", new HTMLEditorField("AutoResponder", "Auto-responder Body")); $this->extend('updateCMSFields', $fields); return $fields; }
public function __construct() { parent::__construct(); $layoutExamples = array(); $layoutExamples[] = new Example('Markup Inheretence', MarkupInheritancePage::getIdentifier()); $layoutExamples[] = new Example('Panels', PanelPage::getIdentifier()); $layoutExamples[] = new Example('Borders', BorderPage::getIdentifier()); $generalExamples = array(); $generalExamples[] = new Example('Labels', LabelPage::getIdentifier()); $generalExamples[] = new Example('Links', LinkPage::getIdentifier()); $generalExamples[] = new Example('Lists', ListPage::getIdentifier()); $generalExamples[] = new Example('Tabs', TabPanelPage::getIdentifier()); $formExamples = array(); $formExamples[] = new Example('Form Fields', FormPage::getIdentifier()); $formExamples[] = new Example('Validation', ValidationPage::getIdentifier()); $formExamples[] = new Example('Special Fields', SpecialFields::getIdentifier()); $tableExamples = array(); $tableExamples[] = new Example('Data Table', DataTablePage::getIdentifier()); $ajaxExamples = array(); $ajaxExamples[] = new Example('Ajax Link', AjaxLinkPage::getIdentifier()); $ajaxExamples[] = new Example('Ajax Button', AjaxButtonPage::getIdentifier()); $authoExamples[] = new Example('Authorised Access Page', AuthorisedPage::getIdentifier()); $examples = array(); $examples[] = new ExampleType('General', $generalExamples); $examples[] = new ExampleType('Layout', $layoutExamples); $examples[] = new ExampleType('Form Components', $formExamples); $examples[] = new ExampleType('Data Tables', $tableExamples); $examples[] = new ExampleType('Ajax', $ajaxExamples); $examples[] = new ExampleType('Security', $authoExamples); $self = $this; $this->add(new ListView('examples', function (picon\ListItem $item) use($self) { $type = $item->getModelObject(); $item->add(new picon\Label('title', new picon\BasicModel($type->name))); $item->add(new ListView('list', function (picon\ListItem $item) use($self) { $link = new picon\Link('link', function () use($item, $self) { $self->setPage($item->getModelObject()->page); }); $item->add($link); $link->add(new picon\Label('exampleName', new picon\BasicModel($item->getModelObject()->name))); }, new picon\ArrayModel($type->examples))); }, new ArrayModel($examples))); }
function ValidateInput() { if ($_SERVER['CONTENT_LENGTH'] > getPhpConfBytes()) { FormPage::GetInstance()->SetErrors(array(array('field' => 'Form', 'err' => _T('The form is attempting to send more data than the server allows. Please check that you are not uploading too many large files.')))); return 1; } $cfg = Config::GetInstance()->GetConfig('rules'); if ($cfg === false) { return 1; } $validator = new Validator(); $conditionals = new Conditionals(); foreach ($cfg as $name => $rules) { // skip all rules that have a name with a _ prefix if ($name[0] == '_') { continue; } if ($conditionals->IsFieldIgnored($name)) { continue; } $fieldtype = $rules->fieldtype; if (method_exists('Validator', $fieldtype)) { if (!$validator->required($name, $rules)) { continue; } else { $validator->{$fieldtype}($name, $rules); } } else { writeErrorLog('Validation handler missing for fieldtype: ', $fieldtype); } } $errcount = count($validator->errors); // ready, assign the result to the page instance if ($errcount > 0) { FormPage::GetInstance()->SetErrors($validator->errors); } else { FormPage::GetInstance()->SetPostValues($validator->post); } return $errcount; }
function myErrorHandler($errno, $errstr, $errfile, $errline) { // some fopen() may fail because the files are optional if (strpos($errstr, 'fopen') !== false) { return false; } $page = FormPage::GetInstance(); // the rules may contain an invalid regexp if (strpos($errstr, 'preg_match') !== false && strpos($errfile, 'validator.inc.php') !== false) { $msg = _T('Error validating RegEx magic field') . substr($errstr, strrpos($errstr, ':')); } else { // default message $msg = 'Warning: [ err ' . $errno . '/line ' . $errline . substr($errfile, strrpos($errfile, '/')) . '] ' . $errstr; } if ($page) { $page->SetErrors(array(array('warn' => $msg))); } else { $errors = array('warn' => $msg); include 'fbapp/inc/displayerrors.inc.php'; exit(0); } return true; }
<title>CoffeeCup Form Builder</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="robots" content="noindex,nofollow" /> <style> .error { color: #142dcc; } .warning { color: #007748; font-style: italic; } </style> </head> <body> <h4><?php echo _T('Your form could not be submitted for the following reason(s):'); ?> </h4> <ul> <?php $page =& FormPage::GetInstance(); if ($page) { $myErrors = $page->GetErrors(); } else { if (isset($errors)) { $myErrors = $errors; } else { $myErrors = array('err' => 'Unspecified error.'); } } foreach ($myErrors as $error) { if (isset($error['err'])) { printf('<li class="error">%s</li>', $error['err']); } if (isset($error['warn'])) { printf('<li class="warning">%s</li>', $error['warn']);
protected function _UpdateRow() { $fields = ''; $rules = Config::GetInstance()->GetConfig('rules'); $data = array(); // deal with the data in the post map foreach ($this->post as $key => $value) { $fields .= $this->_EscapeName($key) . '=?,'; // check rules for special formatting needs if (isset($rules->{$key}) && $rules->{$key}->fieldtype == 'date' && !empty($value)) { $data[] = date('Y-m-d', $value); } else { if ($key == '_submitted_') { $data[] = $this->_applyTimeZone($value); } else { $data[] = $value; } } } // add any file fields that aren't included yet foreach (FormPage::GetInstance()->uploads as $upload) { if (!isset($this->post[$upload['fieldname']])) { $fields .= $this->_EscapeName($upload['fieldname']) . '=?,'; $data[] = $upload['storedname']; } } $sql = 'UPDATE ' . $this->_EscapeName($this->table) . ' SET' . rtrim($fields, ',') . ' WHERE _rowid_=' . $this->lastrowid; $sth = $this->db->prepare($sql); if ($sth === false) { writeErrorLog('Failed compile query:', $sql); return false; } else { if (!$sth->execute($data)) { writeErrorLog('Failed to update data in from table:', $sth->errorInfo()); return false; } } return true; }
public function getFormPost() { return FormPage::GetInstance()->post; }
public function LoadConfig($sdrive_config = null) { // load sdrive first, because the setting is needed to load the rest. if ($sdrive_config) { $this->sdrive =& $sdrive_config; if (isset($this->sdrive['sdrive_account_formbuilder_stats']) && !empty($this->sdrive['sdrive_account_formbuilder_stats'])) { FormPage::GetInstance()->SetStats($this->sdrive); } } // always record times in UTC, apply time zones only when displaying date_default_timezone_set('UTC'); $txt = file_get_contents($this->sdrive ? CONFIG_FILE_SDRIVE : CONFIG_FILE, FILE_USE_INCLUDE_PATH); if ($txt === false) { writeErrorLog('Couldn\'t open or read:', CONFIG_FILE); echo '<html><body>Configuration missing.</body></html>'; exit; } $this->config = json_decode(substr($txt, strpos($txt, "{"))); if ($this->config == NULL) { FormPage::GetInstance()->SetErrors(array(array('err' => 'Failed to read or decode form configuration.'))); writeErrorLog('Couldn\'t decode:', $this->sdrive ? CONFIG_FILE_SDRIVE : CONFIG_FILE); return false; } // move all settings that are not fields 1 level up if (isset($this->config->rules->_special)) { $this->config->special = $this->config->rules->_special; unset($this->config->rules->_special); } $tz = $this->GetConfig('settings', 'general_settings', 'timezone'); if ($tz) { try { $this->user_timezone = new DateTimeZone($tz); } catch (Exception $e) { writeErrorLog('Problem setting Timezone "' . $tz . '", error message:', $e->getMessage()); FormPage::GetInstance()->SetErrors(array(array('err' => 'Failed to set the timezone, check CoffeeCup FormBuilder\'s Settings->General tab for your timezone setting.'))); } } #print_r( $this->config ); }
public function getApplicationName() { // use the form name with a prefix that allows us to recognize the FB app. return FBAPP_PREFIX . FormPage::GetInstance()->GetFormName(); }
private function _GooglePay() { Config::GetInstance()->InitSession(); $payment = new CheckoutController(); $msg = $payment->DoGoogleCheckout(); if (!empty($msg)) { FormPage::GetInstance()->SetErrors(array(array('field' => 'Form', 'err' => $msg))); } }
private function _PaymentFormSubstitutions(&$needles, &$replacements) { $needles[] = _T('[_form_invoicetext_]'); $needles[] = _T('[_form_price_]'); $needles[] = _T('[_cart_total_]'); if (!$this->cart) { // cart may be empty $replacements[] = ''; $replacements[] = ''; $replacements[] = ''; return; } if ($price = $this->cart->getSubtotalPriceProduct(FormPage::GetInstance()->GetFormName())) { $replacements[] = $this->cart->getName(FormPage::GetInstance()->GetFormName()); $replacements[] = $this->cursym . formatMoney($price, $this->divider); } else { $replacements[] = ''; $replacements[] = ''; } $replacements[] = $this->cursym . formatMoney($this->cart->getGrandTotalCart(), $this->divider); }
/** * CoffeeCup Software's Web Form Builder. * * Functions to merge posted data into the HTML form definition. * * * @version $Revision: 2456 $ * @author Cees de Gruijter * @category FB * @copyright Copyright (c) 2011 CoffeeCup Software, Inc. (http://www.coffeecup.com/) */ function MergeFormPost($post = false) { if (!$post) { $post =& $_POST; } $dom = new DOMDocument('1.0', 'UTF-8'); if (!$dom->loadHTML(FormPage::GetInstance()->source)) { writeErrorLog('Failed to parse HTML form.'); return; } $errors = FormPage::GetInstance()->GetErrors(true); $processed_names = array(); $display_max_error = Config::GetInstance()->GetConfig('special', 'maxnumerrors'); if ($display_max_error === false) { $display_max_error = 1000; } // some ridiculously large number // get all input nodes with a name $xpath = new DOMXpath($dom); foreach ($xpath->query('//input[@name]') as $e) { $tagname = $e->getAttribute('name'); $tagname_stripped = str_replace('[]', '', $tagname); // checkboxes have a names like "check1[]", but only "check1" is present in $post if (isset($post[$tagname]) || isset($post[$tagname_stripped])) { switch ($e->getAttribute('type')) { case 'radio': if ($e->getAttribute('value') == $post[$tagname]) { $e->setAttributeNode(new DOMAttr('checked', 'checked')); } break; case 'checkbox': if (isset($post[$tagname_stripped]) && is_array($post[$tagname_stripped]) && in_array($e->getAttribute('value'), $post[$tagname_stripped])) { $e->setAttributeNode(new DOMAttr('checked', 'checked')); } break; case 'file': break; default: $e->setAttributeNode(new DOMAttr('value', $post[$tagname])); } } if (!empty($tagname_stripped) && !in_array($tagname_stripped, $processed_names)) { if ($display_max_error > 0) { InserErrorLabel($dom, $e, $errors); --$display_max_error; } $processed_names[] = $tagname_stripped; } } // get all select nodes with a name foreach ($xpath->query('//select[@name]') as $e) { // findout if the name is defined as an array[] or as a scalar $name = $e->getAttribute('name'); $is_array = false; if (($p = strpos($name, '[]')) !== false) { $name = substr($name, 0, -2); $is_array = true; } if (isset($post[$name])) { foreach ($e->getElementsByTagName('option') as $child) { // set or unset the selected attribute if ($is_array) { if (in_array($child->getAttribute('value'), $post[$name]) && !$child->hasAttribute('selected')) { $child->setAttributeNode(new DOMAttr('selected', 'selected')); } else { if ($child->hasAttribute('selected')) { $child->removeAttribute('selected'); } } } else { if ($child->getAttribute('value') == $post[$name] && !$child->hasAttribute('selected')) { $child->setAttributeNode(new DOMAttr('selected', 'selected')); } else { if ($child->hasAttribute('selected')) { $child->removeAttribute('selected'); } } } } } if (!empty($name) && !in_array($name, $processed_names)) { InserErrorLabel($dom, $e, $errors); $processed_names[] = $name; } } // get all textarea nodes with a name foreach ($xpath->query('//textarea[@name]') as $e) { $name = $e->getAttribute('name'); if (isset($post[$name])) { $e->appendChild($dom->createTextNode($post[$name])); } if (!in_array($name, $processed_names)) { InserErrorLabel($dom, $e, $errors); $processed_names[] = $name; } } // reCaptcha error should also be placed underneath the field if (isset($errors['reCaptcha'])) { $node = $dom->createElement('label', $errors['reCaptcha']); $node->setAttributeNode(new DOMAttr('for', 'fb-captcha_control')); $node->setAttributeNode(new DOMAttr('class', 'error')); $dom->getElementById('fb-captcha_control')->appendChild($node); $processed_names[] = 'reCaptcha'; } // add errors from fields that we haven't processed yet to the error div MakeErrorNode($dom, $errors, $processed_names); return $dom->saveHTML(); }
public function getCMSFields() { $fields = parent::getCMSFields(); $fields->addFieldToTab('Root.Content.Categories', new GridField('JobCategories', 'Job Categories', $this->JobCategories(), GridFieldConfig_RecordEditor::create()->addComponent(new GridFieldSortableRows('SortOrder'), 'GridFieldButtonRow'))); $fields->addFieldToTab('Root.Content.Jobs', new GridField('Positions', 'Position', $this->Positions(), GridFieldConfig_RecordEditor::create()->addComponent(new GridFieldSortableRows('SortOrder'), 'GridFieldButtonRow'))); return $fields; }
function _SubstituteAddress($name) { $matches = array(); $r = preg_match_all('\'\\[([^\\]]+)\\]\'', $name, $matches, PREG_PATTERN_ORDER); if ($r === false) { writeErrorLog('Error in regex parsing:', $name); } if (!$r) { return trim($name); } foreach ($matches[1] as $match) { // check if this is an email field and get its value if it is $match = strtolower($match); if ((Config::GetInstance()->GetConfig('rules', $match, 'fieldtype') == 'email' || Config::GetInstance()->GetConfig('rules', $match, 'contactList')) && isset(FormPage::GetInstance()->post[$match])) { $name = str_ireplace('[' . $match . ']', FormPage::GetInstance()->post[$match], $name); } } return trim($name); }
protected function setError($msg) { // follow the same format that validator is using, thus errors // are an array of key-value pair maps. FormPage::GetInstance()->SetErrors(array(array('err' => $msg))); }
private function _makePublicUrl($fieldname, $filename) { // ensure the publicly visible folder exists if (!file_exists(Config::GetInstance()->getStorageFolder(4))) { mkdir(Config::GetInstance()->getStorageFolder(4)); } // use the rules to find out where the file is if (Config::GetInstance()->GetRulePropertyByName($fieldname, 'files') == true) { if (!copy(Config::GetInstance()->getStorageFolder(1) . $filename, Config::GetInstance()->getStorageFolder(4) . $filename)) { writeErrorLog('MailChimp plugin couldn\'t copy the uploaded file to a public folder', $filename); $this->setError(_T('Failed to copy the uploaded file %s to a publicly visible folder.', $filename)); return; } } else { // look for it in the uploads table if (isset($_FILES[$fieldname]) && file_exists($_FILES[$fieldname]['tmp_name'])) { $filename = SaveUploadAsFile(Config::GetInstance()->getStorageFolder(4), $_FILES[$fieldname]); if ($filename == false) { writeErrorLog('MailChimp plugin couldn\'t move the uploaded file to a public folder', $filename); $this->setError(_T('Failed to move the uploaded file %s to a publicly visible folder.', $filename)); return; } } } $servername = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME']; $path = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $_SERVER['PHP_SELF']; $path = substr($path, 0, strrpos($path, '/')); // encode the folders, not the '/'! $tmp = explode('/', $path); for ($i = 0; $i < count($tmp); ++$i) { $tmp[$i] = rawurlencode($tmp[$i]); } $path = implode('/', $tmp); // windows servers may set [HTTPS] => off, linux server usually don't set [HTTPS] at all if (isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') { $protocol = 'https'; } else { $protocol = 'http'; } $url = $protocol . '://' . $servername; // only add the serverport when it differs from the default if (strpos($servername, ':') === false && ($_SERVER['SERVER_PORT'] != '80' || $protocol != 'http')) { $url .= ':' . $_SERVER['SERVER_PORT']; } return $url . $path . '/' . FormPage::GetInstance()->GetFormName() . CC_FB_STORAGE_FOLDER . CC_FB_PUBLIC_DIRECTORY . $filename; }