/** * Insert the submitted form into the specified Mysql database. */ public function run() { if (count($this->_fieldMap) == 0) { throw new Exception('Mysql success handler: field map is empty'); } $link = @mysql_connect($this->_host, $this->_username, $this->_password); if (!$link) { throw new Exception('Mysql error: ' . mysql_error()); } $db = @mysql_select_db($this->_dbname); if (!$db) { throw new Exception('Mysql error: ' . mysql_error()); } $queryParts = array(); $elements = $this->_form->getElements(); foreach ($this->_fieldMap as $elementName => $fieldName) { if (array_key_exists($elementName, $elements)) { $element = $elements[$elementName]; $value = $element->getValue(); if (is_array($value)) { $value = join(', ', $value); } $queryParts[] = "`{$fieldName}` = '" . mysql_real_escape_string($value) . "'"; } } if (count($queryParts) == 0) { throw new Exception('Mysql success handler: query is empty'); } if (strtolower($this->_form->getCharset()) == 'utf-8') { $utf8Query = "SET NAMES utf8"; $utf8Result = @mysql_query($utf8Query); if (!$utf8Result) { throw new Exception('Mysql error: ' . mysql_error()); } } $query = "INSERT INTO `{$this->_table}` SET " . join(', ', $queryParts); $result = @mysql_query($query); if (!$result) { throw new Exception('Mysql error: ' . mysql_error()); } @mysql_close($link); }
/** * Get the list of IDs of all elements in the given group * * @param iPhorm $form * @param iPhorm_Element_Groupstart $group * @return array */ function iphorm_get_group_element_ids($form, $group) { $groupElementIds = array(); $startCapture = false; $depth = 0; $elements = $form->getElements(); foreach ($elements as $element) { if ($element instanceof iPhorm_Element_Groupstart) { if ($element->getId() == $group->getId()) { // We've found ths group, so start capturing element IDs $startCapture = true; $depth++; continue; } else { if ($startCapture) { // This is another group inside it, so increment depth $depth++; } } } elseif ($element instanceof iPhorm_Element_Groupend) { // This is a group end element so decrement depth if ($startCapture) { if (--$depth == 0) { // This is the group end for our target group so we're done break; } } } else { if ($startCapture) { $groupElementIds[] = $element->getId(); } } } return $groupElementIds; }
/** * Set the default value * * Replaces placeholder tags * * @param string $value */ public function setDefaultValue($value) { $this->_defaultValue = iPhorm::replacePlaceholderValues2($value); }
<?php /** * iPhorm initialisation * * You shouldn't need to change this file unless there is a problem */ define('IPHORM_ROOT', realpath(dirname(__FILE__))); require_once IPHORM_ROOT . '/classes/iPhorm.php'; iPhorm::registerAutoload(); if (get_magic_quotes_gpc()) { $_POST = stripslashes_deep($_POST); } function stripslashes_deep($value) { if (is_array($value)) { $value = array_map('stripslashes_deep', $value); } else { $value = stripslashes($value); } return $value; } $configSuffix = isset($_GET['form']) ? trim(strip_tags($_GET['form'])) : ''; $configFile = strlen($configSuffix) > 0 ? "config-{$configSuffix}.php" : 'config.php'; if (file_exists(IPHORM_ROOT . '/' . $configFile)) { $form = new iPhorm(); require_once IPHORM_ROOT . '/' . $configFile; echo $form->process(); }
/** * Sets the default value dynamically * * @param string key */ public function setDynamicDefaultValue($key) { $value = ''; $dynamicValues = $this->_form->getDynamicValues(); if (isset($dynamicValues[$key])) { $value = $dynamicValues[$key]; } if (isset($_GET[$key])) { $value = $_GET[$key]; } $value = $this->prepareDynamicValue($value); $value = apply_filters('iphorm_element_value', $value, $key); $value = apply_filters('iphorm_element_value_' . $key, $value, $key); if (!empty($value)) { $this->setDefaultValue($value, false); $this->setValue($this->getDefaultValue()); } }
/** * Set the CSS styles * * @param array $styles */ public function setStyles(array $styles) { foreach ($styles as $style) { if (isset($style['type']) && isset($style['css'])) { $this->_styles[$style['type']] = iPhorm::parseCss($style['css']); } } }
/** * Set the default value * * Replaces placeholder tags * * @param string $value * @param boolean $replacePlaceholders Whether or not to replace placeholder values */ public function setDefaultValue($value, $replacePlaceholders = true) { $this->_defaultValue = $replacePlaceholders ? iPhorm::replacePlaceholderValues2($value) : $value; }
/** * Set the group background colour * * @param string $colour The CSS hex colour */ public function setBackgroundColour($colour) { if ($colour) { $this->_backgroundColour = iPhorm::parseCss('background-color: ' . $colour . ';'); } else { $this->_backgroundColour = null; } }