function sprint_form($f, $prefill = array()) { $value = array(); $msg = array(); if (isset($_GET['error']) && ($error = dec_signed_data($_GET['error']))) { $value = $error['value']; $msg = $error['msg']; } $hmac_key = sprint_singular("SELECT value FROM config WHERE `key` = 'HMAC_KEY'"); if ($f['post']) { $method = 'POST'; $prefix = 'do_'; } else { $method = 'GET'; $prefix = ''; } $out = '
\n"; return $out; } function validate_form_date($date) { if (!is_date($date)) return 'ongeldige datum'; return false; } function validate_form_email($email) { if (!filter_var($email, FILTER_VALIDATE_EMAIL)) return 'ongeldig emailadres'; return false; } function validate_form($f, &$out) { foreach ($f['controls'] as $c) { if (!isset($_POST[$c['name']])) internal_error('field '.$c['name'].' missing from POST data'); if ($_POST[$c['name']] == '') { if ($c['required']) $error['msg'][$c['name']] = 'mag niet leeg zijn'; continue; } $error['value'][$c['name']] = $_POST[$c['name']]; if (isset($c['validator']) && ($msg = $c['validator']($_POST[$c['name']]))) { $error['msg'][$c['name']] = $msg; continue; } if (isset($c['pp'])) $out[$c['name']] = $c['pp']($_POST[$c['name']]); else $out[$c['name']] = $_POST[$c['name']]; if (isset($c['pp_maxlength']) && strlen($out[$c['name']]) > $c['pp_maxlength']) { $error['msg'][$c['name']] = 'input te lang, max is '.$c['maxlength'].' bytes'; continue; } } if (isset($error['msg'])) { header('Location: '.$f['name'].'?error='.urlencode(enc_signed_data($error))); exit; } return $error; } ?>