From this page you can download a smart form script, that almost needs no configuring, but still handles posted forms very securely. This form is an ideal solution if you don’t have an extended programming knowledge and yet want to have a highly configurable form. The form configuration is done by special attributes in the html of the form. The visitor of you site will not get to see these attributes.
The comments in the script will help you to understand and configure the script. All files visible below are available in an archive:
.
For your convenience the three files in this archive are listed below, with added syntax coloring. A working example of this form can be seen here. This example will not send any mails however, to prevent the sending of spam mails.
An example pageThis is an example of an contact page that contains the dynamically generated form.

0001<?php0002//This PHP block MUST be placed at the absolute top of the document. Make sure you haven't placed any kind of whitespace or text before it! Otherwise PHP won't be able to send the headers that are required for correct functioning of the form.0003
0004require_once("formchecker.php");
0005?>0006<!DOCTYPE html PUBLIC "-//W3CDTD XHTML 1.0 TransitionalEN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">0007<html xmlns = "http://www.w3.org/1999/xhtml">0008<head>0009<meta http-equiv = "Content-Type" content = "text/html; charset = utf-8" />0010<title>Formuliervalidatie</title>
0011<link href = "form.css" rel = "stylesheet" type = "text/css" />0012</head>0013
0014<body>0015<?php0016$checker = new formchecker();
0017?>0018<h1>Formulier</h1>
0019
0020<form action = "" method = "post">0021<ul>0022 <li class = "required minlength-8 maxlength-60 name-opmerking"><label for = "opmerking">type hier een opmerking</label> *<input type = "text" id = "opmerking" name = "opmerking" value = "" /></li>
0023 <!--with the class "required" in the li you mark a field as such. This is the only special class that will not be removed by the script, so you can give required fields a special lay-out, should you wish so-->0024 <!--with a class "type" followed by a hyphen and then the type of the field, you configure the validation of the field. For example: a field in a li with the class type-email must contain a valid e-mail address-->0025 <!--with a class "name" followed by a hyphen and then the name of the field, you configure the name and id of the field-->0026 <!--the class "sendconfirmationhere" marks a field that will receive the e-mail address of the visitor; confirmation mails will be sent there-->0027 <li class = "required type-email sendconfirmationhere name-email"><label for = "email">vul een geldig e-mailadres in</label> *<input type = "text" id = "email" name = "email" value = "" /></li>
0028
0029 <!--with a class "expected" followed by a hyphen and then the expected value of the field, you configure the required value of a field. Great for checking that a checkbox has indeed been checked ("expected-on")-->0030 <li class = "required expected-on name-ch"><label for = "ch">vink aan</label> *<input type = "checkbox" id = "ch" name = "ch" /></li>
0031
0032
0033 <!--with a class "valid" followed by a hyphen and one or more names separated by hyphens you signify valid fieldnames. Great for dropdowns or radiogroups, when you want to ensure that a hacker will not be able to inject fieldnames in a form that you didn't configure-->0034 <li class = "required valid-radio1-radio2 name-RadioGroup1">Maak een keuze0035 <ul>0036 <li><label for = "RadioGroup1_0">eerste keuze</label> *
0037 <input type = "radio" name = "RadioGroup1" value = "radio1" id = "RadioGroup1_0" />0038 Radio</label></li>
0039 <li><label>tweede keuze</label> *
0040 <input type = "radio" name = "RadioGroup1" value = "radio2" id = "RadioGroup1_1" />0041 Radio</li>0042 </ul>0043 </li>0044
0045 <li class = "required valid-een-twee name-test"><label for = "test">keuze verplicht</label> *<select id = "test" name = "test">
0046 <option value = "...">maak een keuze...</option>
0047 <option value = "een">een</option>
0048 <option value = "twee">twee</option>
0049 </select></li>
0050
0051 <!--with a class "minlength" and/or "maxlength" followed by a hyphen and a number you configure the required minimal length and/or the allowed maximal length of the field's content-->0052 <li class = "required minlength-8 maxlength-120 name-zo"><label for = "zo">dit veld is verplicht</label> *<textarea id = "zo" name = "zo"></textarea></li>
0053
0054 <li id = "knoppen"><input type = "submit" value = "Verzend" name = "verzend" id = "verzend" /></li>
0055 </ul>0056</form>0057
0058<!--within the element "tagBevestigingInBrowser" you can define the html that the visitor will see in his or her browser after submitting the form. The marker "( (gegevens))" will be dynamically replaced with the data the visitor posted. If the visitor has given an e-mail address, within the element tagInzenderEmailadres the marker "( (e-mailadres))" will be replaced with the e-mail address given. Otherwise the element will be removed from the html.-->0059<tagBevestigingInBrowser>0060<!--0061 * Deze html wordt gebruikt voor de weergave van de bevestiging van een inzending in de browser.
0062 * Je kunt de tekst in de H1 en de P aanpassen maar let op het volgende:
0063 * Laat het element <tagInzenderEmailadres> en de code hieronder exact zo staan: hier wordt het e-mailadres van de inzender dynamisch ingevuld, indien het is opgegeven.0064 * Op de plek van worden de waarden van de door de bezoeker ingevulde velden geplaatst, dus laat ook deze code ongemoeid.
0065 * Laat ook de tags <tagBevestigingInBrowser> staan, deze zijn nodig, deze verzorgen het bericht in de browser.0066-->
0067<h1>Formulier verzonden</h1>
0068<p>Bedankt voor uw reactie! <tagInzenderEmailadres>Er is een bevestigingsmail verzonden naar .</tagInzenderEmailadres></p>
0069<p>Dit zijn de gegevens zoals u die ons toegestuurd hebt:</p>
0070
0071
0072</tagBevestigingInBrowser>0073
0074<?php0075$checker->check();0076?>0077
0078</body>0079</html>
This is an example of an contact page that contains the dynamically generated form.
0001<?php0002//This PHP block MUST be placed at the absolute top of the document. Make sure you haven't placed any kind of whitespace or text before it! Otherwise PHP won't be able to send the headers that are required for correct functioning of the form.0003
0004require_once("formchecker.php");
0005?>0006<!DOCTYPE html PUBLIC "-//W3CDTD XHTML 1.0 TransitionalEN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">0007<html xmlns = "http://www.w3.org/1999/xhtml">0008<head>0009<meta http-equiv = "Content-Type" content = "text/html; charset = utf-8" />0010<title>Formuliervalidatie</title>
0011<link href = "form.css" rel = "stylesheet" type = "text/css" />0012</head>0013
0014<body>0015<?php0016$checker = new formchecker();
0017?>0018<h1>Formulier</h1>
0019
0020<form action = "" method = "post">0021<ul>0022 <li class = "required minlength-8 maxlength-60 name-opmerking"><label for = "opmerking">type hier een opmerking</label> *<input type = "text" id = "opmerking" name = "opmerking" value = "" /></li>
0023 <!--with the class "required" in the li you mark a field as such. This is the only special class that will not be removed by the script, so you can give required fields a special lay-out, should you wish so-->0024 <!--with a class "type" followed by a hyphen and then the type of the field, you configure the validation of the field. For example: a field in a li with the class type-email must contain a valid e-mail address-->0025 <!--with a class "name" followed by a hyphen and then the name of the field, you configure the name and id of the field-->0026 <!--the class "sendconfirmationhere" marks a field that will receive the e-mail address of the visitor; confirmation mails will be sent there-->0027 <li class = "required type-email sendconfirmationhere name-email"><label for = "email">vul een geldig e-mailadres in</label> *<input type = "text" id = "email" name = "email" value = "" /></li>
0028
0029 <!--with a class "expected" followed by a hyphen and then the expected value of the field, you configure the required value of a field. Great for checking that a checkbox has indeed been checked ("expected-on")-->0030 <li class = "required expected-on name-ch"><label for = "ch">vink aan</label> *<input type = "checkbox" id = "ch" name = "ch" /></li>
0031
0032
0033 <!--with a class "valid" followed by a hyphen and one or more names separated by hyphens you signify valid fieldnames. Great for dropdowns or radiogroups, when you want to ensure that a hacker will not be able to inject fieldnames in a form that you didn't configure-->0034 <li class = "required valid-radio1-radio2 name-RadioGroup1">Maak een keuze0035 <ul>0036 <li><label for = "RadioGroup1_0">eerste keuze</label> *
0037 <input type = "radio" name = "RadioGroup1" value = "radio1" id = "RadioGroup1_0" />0038 Radio</label></li>
0039 <li><label>tweede keuze</label> *
0040 <input type = "radio" name = "RadioGroup1" value = "radio2" id = "RadioGroup1_1" />0041 Radio</li>0042 </ul>0043 </li>0044
0045 <li class = "required valid-een-twee name-test"><label for = "test">keuze verplicht</label> *<select id = "test" name = "test">
0046 <option value = "...">maak een keuze...</option>
0047 <option value = "een">een</option>
0048 <option value = "twee">twee</option>
0049 </select></li>
0050
0051 <!--with a class "minlength" and/or "maxlength" followed by a hyphen and a number you configure the required minimal length and/or the allowed maximal length of the field's content-->0052 <li class = "required minlength-8 maxlength-120 name-zo"><label for = "zo">dit veld is verplicht</label> *<textarea id = "zo" name = "zo"></textarea></li>
0053
0054 <li id = "knoppen"><input type = "submit" value = "Verzend" name = "verzend" id = "verzend" /></li>
0055 </ul>0056</form>0057
0058<!--within the element "tagBevestigingInBrowser" you can define the html that the visitor will see in his or her browser after submitting the form. The marker "( (gegevens))" will be dynamically replaced with the data the visitor posted. If the visitor has given an e-mail address, within the element tagInzenderEmailadres the marker "( (e-mailadres))" will be replaced with the e-mail address given. Otherwise the element will be removed from the html.-->0059<tagBevestigingInBrowser>0060<!--0061 * Deze html wordt gebruikt voor de weergave van de bevestiging van een inzending in de browser.
0062 * Je kunt de tekst in de H1 en de P aanpassen maar let op het volgende:
0063 * Laat het element <tagInzenderEmailadres> en de code hieronder exact zo staan: hier wordt het e-mailadres van de inzender dynamisch ingevuld, indien het is opgegeven.0064 * Op de plek van worden de waarden van de door de bezoeker ingevulde velden geplaatst, dus laat ook deze code ongemoeid.
0065 * Laat ook de tags <tagBevestigingInBrowser> staan, deze zijn nodig, deze verzorgen het bericht in de browser.0066-->
0067<h1>Formulier verzonden</h1>
0068<p>Bedankt voor uw reactie! <tagInzenderEmailadres>Er is een bevestigingsmail verzonden naar .</tagInzenderEmailadres></p>
0069<p>Dit zijn de gegevens zoals u die ons toegestuurd hebt:</p>
0070
0071
0072</tagBevestigingInBrowser>0073
0074<?php0075$checker->check();0076?>0077
0078</body>0079</html>Smart Form class
This is the class that does all the hard work of generating forms, processing posted data and securing them.
0001<?php0002/*
0003CREDITS
0004
0005* Het formulier is verzorgd door Alex Pot van www.smartscripts.nl.
0006* Het is bedoeld voor studenten en cursisten die onze lessen volgen, zodat ze zelfstandig hun eerste projecten kunnen voorzien van een degelijk en betrouwbaar formulier.
0007* Gebruik je dit formulierscript of geef je het door, laat de credits dan intact!
0008
0009*/
0010
0011header("Expires: ".gmdate("D, d M Y H:i:s")." GMT"); // Always expired
0012header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");// always modified
0013header("Cache-Control: no-cache, must-revalidate");// HTTP/1.1
0014header("Pragma: nocache");// HTTP/1.0
0015
0016if (!defined("locaal"))
0017{0018 if (isset($_SERVER, $_SERVER['SERVER_NAME']) && stristr($_SERVER['SERVER_NAME'],"localhost")) {define("locaal",true);} else {define("locaal",false);}
0019}
0020
0021class formchecker {
0022 private $_email_admin = "dwaal@mac.com";
0023
0024 private $_email_onderwerp_admin = "Formulier gepost op "; //code wordt dynamisch vervangen door sitenaam.nl
0025 private $_email_onderwerp_inzender = "De gegevens van het door u op ingezonden formulier";
0026
0027 private $_email_inhoud = "DOOR U INGEVULDE GEGEVENS \n\n"; //wordt in het script dynamisch aangevuld. De code wordt vervangen door de datum van inzending
0028 private $_bevestiging_in_browser = "<h2>Door u ingevulde gegevens</h2>\r\n\r\n<ul class = \"bevestiginginzending\">";
0029
0030 //termen die duiden op acitviteiten van hackers (met | van elkaar gescheiden en binnen () blijvend)0031 private $_verbodentermen = "/(?:\bb?cc\s*:|Content\-Type|\bfrom\s*:|\[(?:url|action|link))/i";
0032
0033
0034 // ======================== SCRIPT HIERONDER ONGEWIJZIGD LATEN ======================0035
0036 private $_velden = Array();
0037 private $_postmodus = false;
0038 private $_textareas = Array();
0039
0040 //speciale aansturingsclasses die uit de classes van de li's verwijderd moeten worden, zodat de bezoeker ze niet te zien krijgt (class required niet verwijderd, omdat die nog van pas kan komen voor de opmaak. class "name" hier niet noemen, omdat die voor de validatie nodig is):0041 private $_remove_classes = Array("expected", "maxlength", "minlength", "sendconfirmationhere", "type", "valid");
0042
0043 private $_inzender_email_veld = ""; //wordt dynamisch ingevuld, indien de inzender een adres heeft opgegeven
0044 private $_inzender_email = ""; //wordt dynamisch ingevuld met de inhoud van het vorige veld, indien de inzender een adres heeft opgegeven
0045
0046 private $_bevestiging_in_browser_template = "";
0047
0048
0049 public function __construct () {
0050
0051 require_once("simple_html_dom.php");
0052
0053 if (isset($_POST, $_POST['verzend']))$this->_postmodus = true;
0054 ob_start();
0055 }
0056
0057 public function check () {
0058 $formulier = ob_get_clean();0059
0060 //bevestingsbericht inlezen uit de html, indien het formulier werd verzonden:0061 if ($this->_postmodus) {
0062 preg_match("/<tagBevestigingInBrowser>(.*?)<\/tagBevestigingInBrowser>/sim", $formulier, $out);
0063 if (isset($out[0]))$this->_bevestiging_in_browser_template = $out[1];
0064
0065 //commentaar uit de html van de bevestiging verwijderen:0066 $this->_bevestiging_in_browser_template = preg_replace("/<!\-\-.*?\-\->/sim", "", $this->_bevestiging_in_browser_template);
0067 }
0068
0069 //bevestigingsbericht verwijderen uit de html:0070 $formulier = preg_replace("/<tagBevestigingInBrowser>.*?<\/tagBevestigingInBrowser>/sim", "", $formulier);
0071
0072 $formulier = str_get_html($formulier); //hier gaan we dus SimpleHtmlDom gebruiken
0073
0074 //zoek naar verplichte velden:0075 $verplichtevelden = $formulier->find('li[class* = required]');
0076
0077 $foutvelden = Array();
0078
0079 if (count($verplichtevelden)) {
0080 //DebugBreak();0081
0082 foreach ($verplichtevelden as $li) {
0083 $this->_get_field_properties_from($li);
0084 }
0085
0086 //indien er niets gepost is, het formulier simpelweg echon:0087 if (!$this->_postmodus) {
0088 $this->_remove_name_classes($formulier);
0089
0090 $this->_whitespace_correct($formulier);
0091 echo $formulier;
0092 }
0093
0094 else { //valideren met PHP
0095 $valide = true;
0096 foreach ($this->_velden as $name => $props) {
0097 if ($props['type'] == "email" && !$this->_validate_email($_POST[$name])) {
0098 $foutvelden[$name] = "Geen geldig e-mailadres ingevuld";
0099 $valide = false;
0100 continue;0101 }
0102 if ($props['valid-values'] && !in_array($_POST[$name], $props['valid-values'])) {
0103 $foutvelden[$name] = "Geen geldige waarde geselecteerd";
0104 $valide = false;
0105 continue;0106 }
0107 if ($props['expected'] && $_POST[$name] != $props['expected']) {
0108 $foutvelden[$name] = "Verwachte waarde niet ingevuld";
0109 $valide = false;
0110 continue;0111 }
0112 if ($props['min-length'] && strlen($_POST[$name]) < $props['min-length']) {
0113 $foutvelden[$name] = "Te weinig tekens";
0114 $valide = false;
0115 continue;0116 }
0117 if ($props['max-length'] && strlen($_POST[$name]) > $props['max-length']) {
0118 $foutvelden[$name] = "Teveel tekens";
0119 $valide = false;
0120 continue;0121 }
0122
0123 //controle op regeleindes in non-textarea's (dat duidt op hackers):0124 if (!in_array($field, $this->_textareas) && preg_match("/(?:\r|\n|[%]0A)/", $_POST[$name]) && !array_key_exists($name, $foutvelden)) {
0125 $foutvelden[$name] = "Ongeldige tekens gebruikt!";
0126 $valide = false;
0127 continue;0128 }
0129
0130 //controle op verboden termen (dat duidt op hackers):0131 if (preg_match($this->_verbodentermen, $_POST[$name]) && !array_key_exists($name, $foutvelden)) {
0132 $foutvelden[$name] = "Verboden termen gebruikt!";
0133 $valide = false;
0134 continue;0135 }
0136 }
0137 }
0138
0139 if ($this->_postmodus && !$valide)$this->_formulier_herinvullen($formulier, $foutvelden);
0140 elseif ($this->_postmodus) $this->_formulier_verzenden();
0141 }
0142
0143 else {0144 $this->_whitespace_correct($formulier);
0145 echo $formulier;
0146 }
0147 }
0148
0149 private function _formulier_herinvullen ($formulier, $foutvelden = Array()) {
0150
0151 $formulier = str_get_html($formulier);
0152
0153 foreach ($_POST as $field => $value) {
0154 if ($this->_velden[$field]['type'] == "textarea") {
0155 $li = $formulier->find("li[class* = name-{$field}]", 0);
0156 if (array_key_exists($field, $foutvelden)) {
0157 $li->class = $li->class . " foutveld";
0158 $li->innertext = $li->innertext . "<span class = \"foutmelding\">" . $foutvelden[$field] . "</span>";
0159 }
0160 //bug: herinvullen van textarea's wordt genegeerd, dus daarom hieronder apart gedaan0161 }
0162
0163 elseif (in_array($this->_velden[$field]['type'], Array("text", "email", "checkbox"))) {
0164 $li = $formulier->find("li[class* = name-{$field}]", 0);
0165 if (array_key_exists($field, $foutvelden)) {
0166 $li->class = $li->class . " foutveld";
0167 $li->innertext = $li->innertext . "<span class = \"foutmelding\">" . $foutvelden[$field] . "</span>";
0168 }
0169
0170 //herinvullen:0171 $veld = $formulier->find("input[name = {$field}]", 0);
0172 if (in_array($this->_velden[$field]['type'], Array("text", "email")))$veld->value = $_POST[$field];
0173 else $veld->checked = "checked";
0174 }
0175
0176 elseif ($this->_velden[$field]['type'] == "select") {
0177 $li = $formulier->find("li[class* = name-{$field}]", 0);
0178 if (array_key_exists($field, $foutvelden)) {
0179 $li->class = $li->class . " foutveld";
0180 $li->innertext = $li->innertext . "<span class = \"foutmelding\">" . $foutvelden[$field] . "</span>";
0181 }
0182 else {0183 //herinvullen:0184 $dropdown = $li->find("select[name = {$field}]", 0);
0185 $dropdown->innertext = preg_replace("/(value\s* = \s*([\"'])" . $_POST[$field] . "\2)/i", "\1 selected = \"selected\"", $dropdown->innertext);
0186 }
0187 }
0188 elseif ($this->_velden[$field]['type'] == "radio") {
0189 $li = $formulier->find("li[class* = name-{$field}]", 0);
0190 if (array_key_exists($field, $foutvelden)) {
0191 $li->class = $li->class . " foutveld";
0192 $li->innertext = $li->innertext . "<span class = \"foutmelding\">" . $foutvelden[$field] . "</span>";
0193 }
0194 else {0195 //herinvullen:0196 $li->innertext = preg_replace("/(value\s* = \s*([\"'])" . $_POST[$field] . "\2)/i", "\1 checked = \"checked\"", $li->innertext);
0197 }
0198 }
0199
0200 } //einde for0201
0202
0203 foreach ($foutvelden as $key => $melding) {
0204 if (!isset($_POST[$key])) { //bijv. checkboxen of radiobuttons worden niet gepost als ze niet aangevinkt zijn en zijn dan dus niet terug te vinden in $_POST
0205 $li = $formulier->find("li[class* = name-{$key}]", 0);
0206 $li->class = $li->class . " foutveld";
0207 $li->innertext = $li->innertext . "<span class = \"foutmelding\">" . $foutvelden[$key] . "</span>";
0208 }
0209 }
0210
0211 $this->_remove_name_classes($formulier);
0212
0213 $formulier = $formulier->save();
0214
0215 foreach ($this->_textareas as $area) {
0216 $formulier = preg_replace("/(<textarea[^>]*?name\s* = \s*[\"']{$area}[\"'][^>]*?>)/i", "\1" . $_POST[$area], $formulier, 1);
0217 }
0218
0219 $this->_whitespace_correct($formulier);
0220 echo $formulier;
0221 }
0222
0223 private function _formulier_verzenden () {
0224 $this->_email_inhoud = str_replace("", date("d-m-Y, H:i:s"), $this->_email_inhoud);
0225
0226 foreach ($_POST as $veld => $value) {
0227 if ($veld == "verzend")continue;
0228
0229 //indien veld met adres van inzender aangegeven en ingevuld, dan dat adres hier inlezen. Hoeft niet meer gevalideerd te worden, want dat heeft het script al in een eerder stadium gedaan:0230 if ($this->_inzender_email_veld != "" && $veld == $this->_inzender_email_veld) {
0231 $this->_inzender_email = $value;
0232 }
0233
0234
0235 $this->_email_inhoud . = "* " . $veld . ": " . $value . "\n\n";
0236 $this->_bevestiging_in_browser . = "<li> " . $veld . ": " . $value . "</li>\r\n";
0237 }
0238 $this->_bevestiging_in_browser . = "</ul>\r\n";
0239
0240 $valid_inzender_adres = ($this->_inzender_email != "" && $this->_validate_email($this->_inzender_email));
0241
0242 if (!locaal) {0243 //als safe mode op server uitgeschakeld is, dan mail met fifth parameter verzenden, zodat het afzenderadres er mooier uitziet en er gereageerd kan worden op de door het script verzonden mailtjes (afzenderadres dan resp. dat van de inzender of dat van de admin)0244 $safe_mode = strtolower(ini_get("safe_mode"));
0245 $use_fifth = (in_array($safe_mode, Array("off", "0")));
0246
0247 $onderwerp = str_replace("", str_replace("www.", "", $_SERVER['SERVER_NAME']), $this->_email_onderwerp_admin);
0248
0249 if (!$use_fifth || !$valid_inzender_adres) {
0250 mail($this->_email_admin, $onderwerp, $this->_email_inhoud);
0251 }
0252 else {0253 mail($this->_email_admin, $onderwerp, $this->_email_inhoud, "From:{$this->_inzender_email}", "-f {$this->_inzender_email}");
0254 }
0255
0256 if ($this->_inzender_email != "" && $valid_inzender_adres) {
0257 $onderwerp = str_replace("", str_replace("www.", "", $_SERVER['SERVER_NAME']), $this->_email_onderwerp_inzender);
0258 if (!$use_fifth) {
0259 mail($this->_inzender_email, $onderwerp, $this->_email_inhoud);
0260 }
0261 else {0262 mail($this->_inzender_email, $onderwerp, $this->_email_inhoud, "From:{$this->_email_admin}", "-f {$this->_email_admin}");
0263 }
0264 }
0265 }
0266
0267 //bevestigingsmelding in browser weergeven:0268 if ($this->_bevestiging_in_browser_template != "") {
0269
0270 if (!$valid_inzender_adres) {
0271 $this->_bevestiging_in_browser_template = preg_replace("/<tagInzenderEmailadres>.*?<\/tagInzenderEmailadres>/sim", "", $this->_bevestiging_in_browser_template);
0272 }
0273 else {0274 $this->_bevestiging_in_browser_template = preg_replace("/<\/?tagInzenderEmailadres>/i", "", $this->_bevestiging_in_browser_template);
0275 $this->_bevestiging_in_browser_template = str_replace("", $this->_inzender_email, $this->_bevestiging_in_browser_template);
0276 }
0277
0278 $this->_bevestiging_in_browser = str_replace("", $this->_bevestiging_in_browser, $this->_bevestiging_in_browser_template);
0279
0280 echo $this->_bevestiging_in_browser;
0281 }
0282 }
0283
0284 private function _whitespace_correct (&$formulier) {
0285 $formulier = preg_replace("/(\s+)</", "\r\n\1<", $formulier);
0286 }
0287
0288 private function _get_field_properties_from ($li) {
0289 $class = $li->class;
0290 $li_html = $li->outertext;
0291 preg_match("/name\-([^\"' ]+)/i", $class, $name);
0292 $name = $name[1];
0293
0294 $type = "text";
0295
0296 if (stristr($li_html, "textarea"))$type = "textarea";
0297 elseif (stristr($li_html, "<select"))$type = "select";
0298 elseif (preg_match("/type\s* = \s*[\"'](radio|checkbox)/i", $li_html, $out)) {
0299 $type = $out[1];
0300 }
0301
0302 if ($type == "textarea")$this->_textareas[] = $name;
0303
0304 $this->_velden[$name] = Array("type" => $type);
0305
0306 if (preg_match("/\btype\-([^\"' ]+)/", $class, $out)) { //bijv. type-email
0307 $this->_velden[$name]['type'] = trim($out[1]);
0308 }
0309
0310 //evt. veld tbv e-mailadres inzender bepalen:0311 if (preg_match("/sendconfirmationhere/", $class, $out)) {
0312 $this->_inzender_email_veld = $name;
0313 }
0314
0315 $this->_velden[$name]['expected'] = (preg_match("/expected\-([^\"' ]+)/", $class, $out)) ? $out[1] : null;
0316 $this->_velden[$name]['min-length'] = (preg_match("/minlength\-(\d+)/", $class, $out)) ? $out[1] : null;
0317 $this->_velden[$name]['max-length'] = (preg_match("/maxlength\-(\d+)/", $class, $out)) ? $out[1] : null;
0318 $this->_velden[$name]['valid-values'] = Array();
0319 if (preg_match("/\bvalid\-([^\"' ]+)/", $class, $out)) {
0320 $this->_velden[$name]['valid-values'] = split("-", trim($out[1]));
0321 }
0322
0323 //classes opschonen, zodat die voor de bezoeker niet zichtbaar worden en zo de werking van het formulier verraden:0324 foreach ($this->_remove_classes as $rclass) {
0325 $class = preg_replace("/\b{$rclass}(?:\-[a-z0-9_\-]+)?/i", "", $class);
0326 }
0327 $class = trim(preg_replace("/\s{2,}/", " ", $class));
0328 $li->class = $class;
0329 }
0330
0331 private function _remove_name_classes (&$formulier) {
0332 $lis = $formulier->find("li[class* = name-]");
0333 foreach ($lis as $li) {
0334 $li->class = preg_replace("/(\s+)?name\-[\-a-z0-9_]+/i", "", $li->class);
0335 }
0336 }
0337
0338 private function _validate_email ($value) {
0339 return preg_match("/^[a-z.0-9_\-]+@[a-z.0-9_\-]+?\.[a-z]{2,5}$/i", $value);
0340 }
0341}
Stylesheet
This is the stylesheet that gives the form it’s lay-out. You can adapt it to your heart’s content.
0001li.foutveld {background: #FFE4E1; border: 1px solid #C00; padding: 5px;margin-top: 1px;}
0002li.foutveld span {display: block;}
0003
0004form {0005 font-weight: bold;
0006 color: #630;
0007}
0008form, fieldset, #knoppen, form ul, form li {0009 width: 43em;
0010}
0011fieldset {0012 font-size: 80%;
0013 padding-bottom: 1em;
0014 /* border: 0; schakelt border van de fieldset uit */0015}
0016
0017form ul, form li {0018 list-style: none;
0019 margin: 0;
0020 padding: 0;
0021 overflow: hidden; /* mocht de tekst in een floating label te hoog worden, dan rekt het dankzij deze instelling de li toch nog op */
0022}
0023 /* Voeg deze regel toe om de stijl van IE (blauw) te overrulen
0024legend {0025 color: #630;
0026} */
0027label {0028 float: left;
0029 clear: left;
0030 color: #630;
0031 font-weight: bold;
0032 text-align: right;
0033 padding-top: .6em;
0034 width: 13em;
0035 padding-right: 1em;
0036}
0037input, textarea, select {0038 font: 100%/150% Verdana, Geneva, sans-serif;
0039}
0040input, textarea {0041 border: 1px solid #630;
0042 margin: .6em;
0043 background: #ECFFFF;
0044 padding: 1px; /* zo interne instellingen voor inputs van bijvoorbeeld Chrome overrulen */
0045}
0046textarea {0047 height: 6em;
0048 width: 20em !important; /* !important: zo verhinder je dat in Chrome of Firerox het veld breder kan worden en daardoor de labeltekst van zijn plek verdringen, wanneer de bezoeker via het driehoekje rechts onderin het tekstveld groter sleept */
0049 overflow: auto; /* deze beter voor IE6 op visible zetten om onnodige scrollbalken te voorkomen */0050}
0051#knoppen {0052 border-width: 0px;
0053}
0054#verzendknop, #wisknop {0055 margin-top: 1em;
0056}
0057#knoppen li {0058 text-align: center;
0059}
0060select#kiesmaand {0061 left: 12.0em;
0062 margin-top: 0.5em;
0063}

