function handle(&$params) { $app =& Dataface_Application::getInstance(); $query =& $app->getQuery(); $this->table =& Dataface_Table::loadTable($query['-table']); $translations =& $this->table->getTranslations(); foreach (array_keys($translations) as $trans) { $this->table->getTranslation($trans); } //print_r($translations); if (!isset($translations) || count($translations) < 2) { // there are no translations to be made trigger_error('Attempt to translate a record in a table "' . $this->table->tablename . '" that contains no translations.', E_USER_ERROR); } $this->translatableLanguages = array_keys($translations); $translatableLanguages =& $this->translatableLanguages; $this->languageCodes = new I18Nv2_Language($app->_conf['lang']); $languageCodes =& $this->languageCodes; $currentLanguage = $languageCodes->getName($app->_conf['lang']); if (count($translatableLanguages) < 2) { return PEAR::raiseError(df_translate('Not enough languages to translate', 'There aren\'t enough languages available to translate.'), DATAFACE_E_ERROR); } //$defaultSource = $translatableLanguages[0]; //$defaultDest = $translatableLanguages[1]; $options = array(); foreach ($translatableLanguages as $lang) { $options[$lang] = $languageCodes->getName($lang); } unset($options[$app->_conf['default_language']]); $tt = new Dataface_TranslationTool(); $form = new HTML_QuickForm('StatusForm', 'POST'); $form->addElement('select', '--language', 'Translation', $options); $form->addElement('select', '--status', 'Status', $tt->translation_status_codes); //$form->setDefaults( array('-sourceLanguage'=>$defaultSource, '-destinationLanguage'=>$defaultDest)); $form->addElement('submit', '--set_status', 'Set Status'); foreach ($query as $key => $value) { $form->addElement('hidden', $key); $form->setDefaults(array($key => $value)); } if ($form->validate()) { $res = $form->process(array(&$this, 'processForm')); if (PEAR::isError($res)) { return $res; } else { header('Location: ' . $app->url('-action=list&-sourceLanguage=&-destinationLanguage=&-translate=') . '&--msg=' . urlencode('Translation status successfully set.')); exit; } } ob_start(); $form->display(); $out = ob_get_contents(); ob_end_clean(); $records =& $this->getRecords(); df_display(array('form' => $out, 'translationTool' => &$tt, 'records' => &$records, 'translations' => &$options, 'context' => &$this), 'Dataface_set_translation_status.html'); }
foreach ($tax_rates as $rate) { $opts[$rate->tax_rate_id] = ucwords($rate->tax_rate); } $form->addElement('html', '<fieldset>'); $form->addElement('header', 'edit_tax_code', 'Edit Tax Code'); $form->addElement('text', 'tax_code', 'Tax Code:', array('size' => 2, 'maxlength' => 2, 'class' => 'inputbox')); $s->loadArray($opts); $form->addElement($s); $form->addElement('text', 'description', 'Description:', array('size' => 20, 'maxlength' => 20, 'class' => 'inputbox')); $form->addElement('html', '</fieldset>'); $form->addRule('description', 'Please enter a decription', 'required'); $form->addRule('tax_code', 'Please enter a tax code', 'required'); $form->addRule('tax_code', 'Tax codes have only letters', 'lettersonly'); if ($form->validate()) { $form->freeze(); $values = $form->process(array(&$this, 'formValues'), false); $menuBar['back'] = '/ushop/tax/overview'; $values['tax_code'] = strtoupper($values['tax_code']); //check then enter the record. $res = $this->update($values, $ushop->db_name . 'tax_codes', array('where' => 'tax_code_id=' . $this->registry->params['id'])); if ($res) { $params['TYPE'] = 'pass'; $params['MESSAGE'] = '<h2>Tax code was successfully edited.</h2>'; } else { $params['TYPE'] = 'error'; $params['MESSAGE'] = '<h2>Tax code could not be edited due to an error.</h2>'; } // done! } else { $form->setDefaults(array('tax_code' => $rows[0]->tax_code, 'tax_rate_id' => $rows[0]->tax_rate_id, 'description' => $rows[0]->description)); $renderer = new UthandoForm(__SITE_PATH . '/templates/' . $template);
function db2app() { require_once 'HTML/QuickForm.php'; $form = new HTML_QuickForm('db2app'); $res = mysql_list_dbs(db()); if (!$res) { trigger_error(mysql_error(db()), E_USER_ERROR); } $options = array('' => 'Please Select Database ...'); while ($row = mysql_fetch_row($res)) { $options[$row[0]] = $row[0]; } $form->addElement('hidden', '-action', 'db2app'); $form->addElement('select', 'database_name', 'Select Database' . $this->infoLink('archive2app.database_name'), $options, array('onchange' => 'listeners.database_name.onchange(this)')); $form->addElement('header', 'db_info', 'Database connection details'); //$form->addElement('html', 'this is a test'); $form->addElement('text', 'mysql_user', 'MySQL Username ' . $this->infoLink('archive2app.mysql_user')); $form->addElement('password', 'mysql_password', 'MySQL Password'); //$form->addElement('radio','output_format','Output options','Download as tar.gz archive','download'); //$form->addElement('radio','output_format','','Install on webserver in apps directory','install'); $form->addElement('select', 'install_type', 'Installation type ' . $this->infoLink('archive2app.install_type'), array('' => 'Please select ...', 'download_tarball' => 'Download Tarball', 'ftp_install' => 'Install on server (using FTP)'), array('onchange' => "listeners.install_type.onchange(this);")); $form->addElement('header', 'ftp_info', 'FTP Connection Info'); $form->addElement('text', 'ftp_host', 'FTP Host'); $form->addElement('checkbox', 'ftp_ssl', 'Use SSL'); $form->setDefaults(array('ftp_host' => DB_HOST)); $form->addElement('text', 'ftp_path', 'FTP Path', array('size' => 50)); $form->setDefaults(array('ftp_path' => $_SERVER['DOCUMENT_ROOT'])); $form->addElement('text', 'ftp_username', 'FTP Username'); $form->addElement('password', 'ftp_password', 'FTP Password'); $form->addElement('submit', 'submit', 'Submit'); $form->addRule('database_name', 'Please select a database', 'required', null, 'client'); $form->addRule('mysql_user', 'Please enter a mysql username that the application can connect as.', 'required', null, 'client'); $form->addRule('install_type', 'Please select an installation type and then click submit.', 'required', null, 'client'); $form->setDefaults(array('mysql_user' => $_SERVER['PHP_AUTH_USER'], 'mysql_password' => $_SERVER['PHP_AUTH_PW'])); if ($form->validate()) { $tarpath = $form->process(array(&$this, 'db2app__process'), true); header('Content-type: application/x-gzip'); header('Content-Disposition: attachment; filename="' . basename($tarpath) . '.tar.gz"'); echo file_get_contents($tarpath); exit; } require_once 'HTML/QuickForm/Renderer/Array.php'; $renderer = new HTML_QuickForm_Renderer_Array(true, true, true); $form->accept($renderer); $context = $renderer->toArray(); //print_r($context); ob_start(); $form->display(); $out = ob_get_contents(); ob_end_clean(); include 'install' . DIRECTORY_SEPARATOR . 'db2app.inc.php'; }
$form->addRule('size', 'Please select a size.', 'required'); $form->addRule('size', 'Please select a size.', 'check_array', array('small' => 1, 'medium' => 1, 'large' => 1)); // The sweet field is required and its value must be in the // $sweets array $form->addRule('sweet', 'Please select a valid sweet item.', 'required'); $form->addRule('sweet', 'Please select a valid sweet item.', 'check_array', $sweets); // The main_dish field is required, it must have exactly two values // and those values must be in the $main_dishes array $form->addRule('main_dish', 'Please select exactly two main dishes.', 'required'); $form->addRule('main_dish', 'Please select exactly two main dishes.', 'check_array_size', 2); $form->addRule('main_dish', 'Please select exactly two main dishes.', 'check_array', $main_dishes); // The main logic of the page: if the submitted form parameters are // valid, then process them by running the save_order() function. // Otherwise, display the form. if ($form->validate()) { $form->process('save_order'); } else { $form->display(); } // The function to do the form processing. It is identical to process_form() // in Chapter 6 except that it accesses the submitted form parameters through // $form_data instead of $_POST function save_order($form_data) { // look up the full names of the sweet and the main dishes in // the $GLOBALS['sweets'] and $GLOBALS['main_dishes'] arrays $sweet = $GLOBALS['sweets'][$form_data['sweet']]; $main_dish_1 = $GLOBALS['main_dishes'][$form_data['main_dish'][0]]; $main_dish_2 = $GLOBALS['main_dishes'][$form_data['main_dish'][1]]; if ($form_data['delivery'] == 'yes') { $delivery = 'do';
$form->addElement("text", "lastName", "Last name"); $form->addElement("text", "emailAddress", "Email address"); $form->addElement("text", "subject", "Message subject"); $form->addElement("textarea", "message", "Message", array("rows" => 10, "cols" => 50)); $form->addElement("submit", "sendButton", "Send Message"); $form->addRule("firstName", "Please enter your first name", "required"); $form->addRule("firstName", "The First Name field can contain only letters, digits, spaces, apostrophes, and hyphens", "regex", "/^[ \\'\\-a-zA-Z0-9]+\$/"); $form->addRule("lastName", "Please enter your last name", "required"); $form->addRule("lastName", "The Last Name field can contain only letters, digits, spaces, apostrophes, and hyphens", "regex", "/^[ \\'\\-a-zA-Z0-9]+\$/"); $form->addRule("emailAddress", "Please enter an email address", "required"); $form->addRule("emailAddress", "Please enter a valid email address", "email"); $form->addRule("subject", "Please enter a message subject", "required"); $form->addRule("subject", "Your subject can contain only letters, digits, spaces, apostrophes, commas, periods, and hyphens", "regex", "/^[ \\'\\,\\.\\-a-zA-Z0-9]+\$/"); $form->addRule("message", "Please enter your message", "required"); if ($form->isSubmitted() and $form->validate()) { $form->process("sendMessage"); } else { echo "<p>Please fill in all the fields below, then click Send Message to send us an email.</p>"; $renderer = new HTML_QuickForm_Renderer_Tableless(); $form->accept($renderer); echo $renderer->toHtml(); } function sendMessage($values) { $recipient = OWNER_FIRST_NAME . " " . OWNER_LAST_NAME . " <" . OWNER_EMAIL_ADDRESS . ">"; $headers = "From: " . $values["firstName"] . " " . $values["lastName"] . " <" . $values["emailAddress"] . ">"; if (mail($recipient, $values["subject"], $values["message"], $headers)) { echo "<p>Thanks for your message! Someone will be in touch shortly.</p>"; } else { echo '<p>Sorry, your message could not be sent.</p>'; echo '<p>Please <a href="javascript:history.go(-1)">go back</a> to the form, check the fields and try again.</p>';
</head> <body> <h1>How many days old are you?</h1> <?php require_once "HTML/QuickForm.php"; require_once "HTML/QuickForm/Renderer/Tableless.php"; $form = new HTML_QuickForm("form", "get", "days_old.php", "", array("style" => "width: 30em;"), true); $form->removeAttribute("name"); $form->setRequiredNote(""); $options = array('format' => "MdY", "minYear" => 1902, "maxYear" => date("Y")); $form->addElement("date", "dateOfBirth", "Your date of birth", $options); $form->addElement("submit", "calculateButton", "Calculate"); $form->addGroupRule("dateOfBirth", "Please enter your date of birth", "required"); $form->addRule("dateOfBirth", "Please enter a valid date", "callback", "checkDateOfBirth"); if ($form->isSubmitted() and $form->validate()) { $form->process("calculateDays"); } $renderer = new HTML_QuickForm_Renderer_Tableless(); $form->accept($renderer); echo $renderer->toHtml(); function checkDateOfBirth($value) { return checkdate($value["M"], $value["d"], $value["Y"]); } function calculateDays($values) { $currentDate = mktime(); $dateOfBirth = mktime(0, 0, 0, $values["dateOfBirth"]["M"], $values["dateOfBirth"]["d"], $values["dateOfBirth"]["Y"]); $secondsOld = $currentDate - $dateOfBirth; $daysOld = (int) ($secondsOld / 60 / 60 / 24); echo "<p>You were born on " . date("l, F jS, Y", $dateOfBirth) . ".</p>";
$storysql = "SELECT * FROM story WHERE id = " . $storyid . ";"; //$storyres = mysql_query($storysql); //$storyrow = mysql_fetch_assoc($storyres); $storyres = $db->query($storysql); $storyrow = $storyres->fetchAll(PDO::FETCH_ASSOC); $form->setDefaults(array('story_id' => $storyid)); $form->setDefaults(array('cat_id' => $storyrow[0]['cat_id'])); $form->setDefaults(array('subject' => $storyrow[0]['subject'])); $form->setDefaults(array('body' => $storyrow[0]['body'])); // Define filters and validation rules $form->applyFilter('subject', 'trim'); $form->addRule('subject', 'Please enter your username', 'required', null, 'client'); $form->applyFilter('body', 'trim'); $form->addRule('body', 'Please enter your username', 'required', null, 'client'); // if form validates, freeze the data and process it if ($form->validate()) { $form->freeze(); $form->process("process_data", false); } else { $form->display(); } // process form data ($values = name/value pairs function process_data($values) { global $db; $sql = "UPDATE story SET cat_id = " . $values['cat_id'] . ", poster_id = " . $_SESSION['POSTERID'] . ", subject = '" . $values['subject'] . "'" . ", body = '" . $values['body'] . "' WHERE id = " . $values['story_id'] . ";"; // mysql_query($sql); $db->query($sql); echo $sql; } require "footer.php";
function process($callback = null, $mergFiles = true) { if (isset($this->_query['--find-submit'])) { return parent::process(array(&$this, 'performFind')); } else { return null; } }
$form->addGroupRule('name', 'Name is required', 'required'); $form->addRule('pass', 'Password must be between 8 to 10 characters', 'rangelength', array(8, 10), 'client'); $form->addRule('country', 'Country is a required field', 'required'); $form->addGroupRule('destination', 'Please check at least two boxes', 'required', null, 2); $form->addGroupRule('phone', 'Please fill all phone fields', 'required'); $form->addGroupRule('phone', 'Values must be numeric', 'numeric'); $AddrRules['zip'][0] = array('Zip code is required', 'required'); $AddrRules['zip'][1] = array('Zip code is numeric only', 'numeric'); $AddrRules['city'][0] = array('City is required', 'required'); $AddrRules['city'][1] = array('City is letters only', 'lettersonly'); $form->addGroupRule('address', $AddrRules); // Tries to validate the form if ($form->validate()) { // Form is validated, then freezes the data $form->freeze(); $form->process('myProcess', false); echo "\n<hr>\n"; } // setup a template object $options =& PEAR::getStaticProperty('HTML_Template_Flexy', 'options'); $options = array('templateDir' => './templates', 'compileDir' => './templates/build', 'forceCompile' => 1, 'debug' => 0, 'local' => 'en'); $template = new HTML_Template_Flexy($options); $renderer =& new HTML_QuickForm_Renderer_ObjectFlexy($template); $renderer->setLabelTemplate("label.html"); $renderer->setHtmlTemplate("html.html"); $form->accept($renderer); $view = new StdClass(); $view->form = $renderer->toObject(); $template->compile("flexy-static.html"); // capture the array stucture ob_start();
function handle(&$params) { $app =& Dataface_Application::getInstance(); $query =& $app->getQuery(); $table =& Dataface_Table::loadTable($query['-table']); $form = new HTML_QuickForm(); foreach ($query as $key => $val) { if ($key[0] == '-' and $key[1] != '-') { $form->addElement('hidden', $key, $val); } } $form->addElement('hidden', '--redirect'); $form->setDefaults(array('--redirect' => $app->url(''))); $form->addElement('text', 'title', 'Title'); $columns = array(); $options = array($query['-table'] => $query['-table']); foreach ($table->relationships() as $rname => $relationship) { $options['::' . $rname] = '::' . $rname; $destTables = $relationship->getDestinationTables(); $rfields = $relationship->fields(true); $fkeys = $relationship->getForeignKeyValues(); //print_r($fkeys); $rcolumns = array(); foreach ($rfields as $rfname) { list($rftable, $rfname) = explode('.', $rfname); if (isset($fkeys[$rftable][$rfname])) { continue; } $columns['::' . $rname][$rname . '.' . $rfname] = $rname . '.' . $rfname; } //foreach ($destTables as $destTable){ // // foreach ($destTable->relationships() as $destRelationshipName => $destRelationship ){ // $options['::'.$rname.'::'.$destRelationshipName] = '::'.$rname.'::'.$destRelationshipName; // // } // unset($destTable); //} } $form->addElement('select', 'table', 'From table', $options, array('onchange' => 'Dataface.modules.DataGrid.newForm.updateFieldsOptions(this);')); $options = array(); foreach ($table->fields() as $fieldName => $fieldDef) { $options[$fieldName] = $fieldName; } $columns[$query['-table']] = $options; $fieldSelector =& $form->addElement('advmultiselect', 'fields', 'Selected Columns', $options); $fieldSelector->setButtonAttributes('moveup', 'class=inputCommand'); $fieldSelector->setButtonAttributes('movedown', 'class=inputCommand'); $form->addElement('submit', 'submit', 'Create Grid'); if ($form->validate()) { $res = $form->process(array(&$this, 'process'), true); if (PEAR::isError($res)) { return $res; } if (@$query['--redirect']) { $url = $query['--redirect']; } else { $url = $app->url(''); } $url = preg_replace('/[&]--[^=]+\\=[^&]*/', '', $url); $url .= '&--msg=' . urlencode('Grid Saved Successfully'); header('Location: ' . $url); exit; } import('HTML/QuickForm/Renderer/ArraySmarty.php'); import('Dataface/SkinTool.php'); $renderer = new HTML_QuickForm_Renderer_ArraySmarty(Dataface_SkinTool::getInstance()); $form->accept($renderer); df_register_skin('DataGrid', DATAFACE_PATH . '/modules/DataGrid/templates'); $json = new Services_JSON(); df_display(array('form' => $renderer->toArray(), 'columns' => $json->encode($columns)), 'DataGrid/new.html'); }
function handle($params) { $app =& Dataface_Application::getInstance(); $query =& $app->getQuery(); $this->table =& Dataface_Table::loadTable($query['-table']); $translations =& $this->table->getTranslations(); foreach (array_keys($translations) as $trans) { $this->table->getTranslation($trans); } //print_r($translations); if (!isset($translations) || count($translations) < 2) { // there are no translations to be made trigger_error('Attempt to translate a record in a table "' . $this->table->tablename . '" that contains no translations.', E_USER_ERROR); } $this->translatableLanguages = array_keys($translations); $translatableLanguages =& $this->translatableLanguages; $this->languageCodes = new I18Nv2_Language($app->_conf['lang']); $languageCodes =& $this->languageCodes; $currentLanguage = $languageCodes->getName($app->_conf['lang']); if (count($translatableLanguages) < 2) { return PEAR::raiseError(df_translate('Not enough languages to translate', 'There aren\'t enough languages available to translate.'), DATAFACE_E_ERROR); } $defaultSource = $translatableLanguages[0]; $defaultDest = $translatableLanguages[1]; $options = array(); foreach ($translatableLanguages as $lang) { $options[$lang] = $languageCodes->getName($lang); } $form = new HTML_QuickForm('TranslationForm', 'POST'); $form->addElement('select', '-sourceLanguage', 'Source Language', $options); $form->addElement('select', '-destinationLanguage', 'Destination Language', $options); $form->setDefaults(array('-sourceLanguage' => $defaultSource, '-destinationLanguage' => $defaultDest)); $form->addElement('submit', '-translate', 'Translate'); $mask =& Dataface_LinkTool::getMask(); // The mask of parameters that are passed to new urls // We need to modify this mask so that the appropriate parameters are passed. foreach ($query as $key => $value) { $form->addElement('hidden', $key); $form->setDefaults(array($key => $value)); } if ($form->validate()) { $res = $form->process(array(&$this, 'processForm')); if (PEAR::isError($res)) { if ($query['--format'] == 'rest') { header('Content-type: text/plain'); echo 'FAILED' . "\n" . $res->getMessage(); exit; } return $res; } else { //print_r($form->exportValues()); //echo "Done";exit; if ($query['--format'] == 'rest') { header('Content-type: text/plain'); echo 'SUCCEEDED' . "\nRecords Successfully Translated"; exit; } header('Location: ' . $app->url('-action=list&-sourceLanguage=&-destinationLanguage=&-translate=') . '&--msg=Records successfully translated'); exit; } } ob_start(); $form->display(); $out = ob_get_contents(); ob_end_clean(); df_display(array('body' => $out), 'Dataface_Main_Template.html'); }
// but then they're out of date after processing create_add_form(); create_choose_form(); // Validate an process or display if (isset($_POST['save'])) { if ($create_pf_form->validate()) { $create_pf_form->process('create_portfolio'); // we've added a portfolio, load a clean create_pf_form and reload the choose $create_pf_form = new HTML_QuickForm('add_portfolio'); create_add_form(); $choose_pf_form = new HTML_QuickForm('choose_portfolio'); create_choose_form(); } } elseif (isset($_POST['choose'])) { if ($choose_pf_form->validate()) { $choose_pf_form->process('choose_portfolio'); header("Location: /queries.php"); exit; } } elseif (isset($_POST['delete'])) { if ($choose_pf_form->validate()) { $data = $choose_pf_form->exportValues(); $pfid = $data['portfolio']; delete_portfolio($pfid); // recreate the choose form since the data has changed $choose_pf_form = new HTML_QuickForm('choose_portfolio'); create_choose_form(); } } // display the forms print '<table border="1" cellpadding="5" cellspacing="0" align="center"><tr><td>';
function process($callback, $mergeFiles = true) { $ret = parent::process($callback, $mergeFiles); $this->resetToken(); return $ret; }
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Roman numerals converter</title> </head> <body> <h1>Roman numerals converter</h1> <?php require_once "HTML/QuickForm.php"; require_once "Numbers/Roman.php"; $form = new HTML_QuickForm("convertForm", "get", "", "", null, true); $form->removeAttribute("name"); $form->addElement("text", "number", "Number (in Arabic or Roman format)"); $form->addElement("submit", "convertButton", "Convert"); $form->addRule("number", "Please enter a number", "required"); if ($form->isSubmitted() and $form->validate()) { $form->process("convertNumber"); } echo $form->toHtml(); function convertNumber($values) { $originalNumber = $values["number"]; if (is_numeric($originalNumber)) { $numerals = "Roman"; $originalNumber = (int) $originalNumber; $convertedNumber = Numbers_Roman::toNumeral($originalNumber, true, true); } else { $numerals = "Arabic"; $originalNumber = preg_replace("/[^IVXLCDM]/i", "", $originalNumber); $convertedNumber = Numbers_Roman::toNumber($originalNumber); } echo "<p>{$originalNumber} in {$numerals} numerals is: {$convertedNumber}.</p>";