Działa, działa! Prawie.
Dochodzą dane poza message
IGN:Talmidah ELEMENT:Earth JOB:Warrior LVL:134 Q1:Moja odp Q2:nie mam pojecia Q3:haha
MESSAGE:q3Tam gdzie powinna być wiadomość jest q3 o.O
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Form</title>
<style type="text/css">
html,body{margin:0;padding:0}
body{background:#eee; color:#000; font:11px/16px verdana,sans-serif}
form{margin:10px; padding:0}
.class1 dt,.class1 dd{display:block; float:left; margin:0; padding:10px 0 0 0}
.class1 dt{width:8em; clear:left}
.class2 dt,.class2 dd{display:block; margin:0; padding:0; clear:left}
.class2 dt{padding-top:10px}
.clear{clear:both}
</style>
<script type="text/javascript">
//<![CDATA[
function trim(s){return s.replace(/^\s*|\s*$/g,'');}
function test_form(f){
var i,n,r,s='Please enter ',e=f.elements,fe=[
{name:'ign', pattern:".{3,}", msg:s+'correct IGN (nick), at least 3 characters'},
{name:'lvl', pattern:"^\\d{1,3}$", msg:s+'proper level, 0-999'},
{name:'q1', pattern:".+", msg:s+'answer'},
{name:'q2', pattern:".+", msg:s+'answer'},
{name:'q3', pattern:".+", msg:s+'answer'}
];
for (i=0, n=fe.length; i < n; ++i) {
r = new RegExp(fe[i].pattern, 'g');
if (!r.test(trim(e[fe[i].name].value))) {
alert(fe[i].msg);
f.elements[fe[i].name].focus();
return false;
}
}
r = false;
for (i=e['element'].length-1; i >= 0; --i) {
if (e['element'][i].checked) {r = true; break;}
}
if (!r) {alert('Please select element'); return false;}
r = false;
for (i=e['job'].length-1; i >= 0; --i) {
if (e['job'][i].checked) {r = true; break;}
}
if (!r) {alert('Please select job'); return false;}
return true;
}
//]]>
</script>
</head>
<body>
<?php
class Request {
private static function _processArray
(&$array) { $array = self::_stripslashesDeep($array);
}
private static function _stripslashesDeep
($value) { }
}
static function getPost
($name) { if (!$called) {
self::_processArray($_POST);
$called = true;
}
return isset($_POST[$name]) ?
$_POST[$name] : null; }
static function getRequestMethod
() { return isset($_SERVER['REQUEST_METHOD']) ?
$_SERVER['REQUEST_METHOD'] : ''; }
}
$error_msg = $message = '';
foreach (array('ign', 'element', 'job', 'lvl', 'q1', 'q2', 'q3') as $v) { $value = Request::getPost($v);
if (strlen((string
)$value) === 0
) { $error_msg .= "<br />\n- no value for '{$v}'";
}
else {
}
}
if (strlen($error_msg) === 0
) { $message .= "MESSAGE:\n {$v}\n";
if (@mail('celcia@windowslive.com', 'application', $message, "MIME-Version: 1.0\r\nContent-type: text/plain; charset=UTF-8\r\n")) { echo '<div style="border:1px solid green;margin:10px;padding:10px">Your request has been sent</div>'; }
else {
echo '<div style="border:1px solid red;margin:10px;padding:10px">There was an error when sending mail</div>'; }
}
else {
echo '<div style="border:1px solid red;margin:10px;padding:10px">Errors in the form: ' . $error_msg . '</div>'; }
}
?>
<form method="post" action="form.php" onsubmit="return test_form(this)">
<dl class="class1">
<dt>IGN:</dt>
<dd><input type="text" name="ign" size="20" value="
<?php echo htmlspecialchars(Request
::getPost('ign')); ?>" /></dd>
<dt>Element:</dt>
<dd><label><input type="radio" name="element" value="Earth" /> Earth</label><br />
<label><input type="radio" name="element" value="Fire" /> Fire</label><br />
<label><input type="radio" name="element" value="Water" /> Water</label><br />
<label><input type="radio" name="element" value="Wind" /> Wind</label></dd>
<dt>Job:</dt>
<dd><label><input type="radio" name="job" value="Killer" /> Killer</label><br />
<label><input type="radio" name="job" value="Warrior" /> Warrior</label><br />
<label><input type="radio" name="job" value="Knight" /> Knight</label><br />
<label><input type="radio" name="job" value="Wit" /> Wit</label><br />
<label><input type="radio" name="job" value="Priest" /> Priest</label><br />
<label><input type="radio" name="job" value="Seer" /> Seer</label></dd>
<dt>LVL:</dt>
<dd><input type="text" name="lvl" size="3" maxlength="3" value="
<?php echo htmlspecialchars(Request
::getPost('lvl')); ?>" /></dd>
</dl>
<dl class="class2">
<dt>Question 1?</dt>
<dd><input type="text" name="q1" size="100" value="
<?php echo htmlspecialchars(Request
::getPost('q1')); ?>" /></dd>
<dt>Question 2?</dt>
<dd><input type="text" name="q2" size="100" value="
<?php echo htmlspecialchars(Request
::getPost('q2')); ?>" /></dd>
<dt>Question 3?</dt>
<dd><input type="text" name="q3" size="100" value="
<?php echo htmlspecialchars(Request
::getPost('q3')); ?>" /></dd>
<dt><br />Your message:</dt>
<dd><textarea name="message" cols="80" rows="5">
<?php echo htmlspecialchars(Request
::getPost('message')); ?></textarea></dd>
</dl>
<p class="clear">Almost all fields are required<br />
<input type="submit" value="Submit" /></p>
</form>
</body></html>