/** * Smarty {fill_form_values}...{/fill_form_values} extension. * Fills in form fields between the tags based on values in Smarty template * variables, and shows form errors stored in the template variable * "formErrors". * * @param array $params Params from smarty template (unused) * @param string $content HTML to filter (it's {...}THIS STUFF{/...} * @param Smarty $smarty * @return string $content with form vars set properly. */ function smarty_fill_form_values($params, $content, &$smarty) { if ($content === null) { return ""; } $vars = $smarty->get_template_vars(); $errors = array(); if (array_key_exists('formErrors', $vars)) { $errors = $vars['formErrors']; } return fillInFormValues($content, $vars, $errors); }
header('Content-Length: ' . (string) strlen($data)); echo $data; exit(0); } ob_start(); include "form.html.inc"; $html = ob_get_contents(); ob_end_clean(); $request = get_magic_quotes_gpc() ? array_map('stripslashes', $_REQUEST) : $_REQUEST; $validationData['address1'] = array('isRequired', 'type' => 'btcdestination'); $validationData['amount1'] = array('isRequired', 'type' => 'btcamount'); $validationData['address2'] = array('type' => 'btcdestination'); $validationData['amount2'] = array('type' => 'btcamount'); $validationData['address3'] = array('type' => 'btcdestination'); $validationData['amount3'] = array('type' => 'btcamount'); if (isset($request['submit'])) { $formErrors = validateForm($request, $validationData); if (count($formErrors) == 0) { $info = createPaymentRequest($request, $formErrors); } if (count($formErrors) == 0) { $html = preg_replace('/<span class="result">[^<]*/', '<span class="result">' . $info, $html); // Normally there would be code here to process the form // and redirect to a thank you page... // ... but for this example, we just always re-display the form. } } else { $formErrors = array(); } echo fillInFormValues($html, $request, $formErrors);
function output($output_string) { $output_web_page = file_get_contents('vorlesungskommentargenerator.html'); $output_web_page = str_replace('<!--OUTPUTHERE-->', $output_string, $output_web_page); $output_web_page = fillInFormValues($output_web_page, $_GET); header('Content-Type: text/html; charset=utf-8'); echo $output_web_page; exit(0); }